2016-05-24 13 views
0

データのインデックス付けにElasticSearchとNESTバージョン2を使用しています。私のデータオブジェクトは、同じタイプの子オブジェクトを持つことができます。私は、特定のフィールドを分析しないことを示す注釈を使用しています。この注釈は親オブジェクトに適用されますが、子オブジェクトには適用されません。私は子供インスタンスを含めるように私の注釈を変更する方法を把握しようとしています。FieldIndexOptionがネストされたオブジェクトに適用されていません

私はこのようなものがあります:次のように私は最初のインデックスを作成すると

public class Person { 
    public int Id {get; set;} 

    [String(Index = FieldIndexOption.NotAnalyzed)] 
    public string Code {get; set;} 

    public Person child {get; set;} 
} 

を:

client.Map<Person>(d => d.AutoMap()); 

マッピングは次のようになります。Iインデックス後

"people": { 
    "mappings": { 
     "person": { 
      "properties": { 
       "id": { 
        "type": "integer" 
       }, 
       "code": { 
        "type": "string", 
        "index": "not_analyzed" 
       }, 
       "child": { 
        "type": "object" 
       } 
      } 
     } 
    } 
} 

一部次のような文書:

これまでの
client.Index(person); 

マッピングの変更:

"people": { 
    "mappings": { 
     "person": { 
      "properties": { 
       "id": { 
        "type": "integer" 
       }, 
       "code": { 
        "type": "string", 
        "index": "not_analyzed" 
       }, 
       "child": { 
        "properties": { 
         "id": { 
          "type": "integer" 
         }, 
         "code": { 
          "type": "string" 
         } 
        } 
       } 
      } 
     } 
    } 
} 

は、私はこのような文書があるとしましょう:

{ 
    "id": 100, 
    "code": "ABC100", 
    "child": { 
     "id": 123, 
     "code": "ABC123" 
    } 
} 

トップレベルの人のCodeフィールドが分​​析されていないされて何が起こります、このような検索を行うことができます:

GET people/_search 
{ 
    "query": { 
    "term": { 
     "code": "ABC100" 
    } 
    } 
} 

しかし、子のコードフィールドはデフォルトのアナライザなので、ABC123はabc123になります。

したがって、これらのすべては、私の文書を検索します:

GET people/_search 
{ 
    "query": { 
    "term": { 
     "child.id": 123 
    } 
    } 
} 
GET people/_search 
{ 
    "query": { 
    "term": { 
     "child.code": "abc123" 
    } 
    } 
} 
GET people/_search 
{ 
    "query": { 
    "match": { 
     "child.id": "ABC123" 
    } 
    } 
} 

しかし、これはしていません:

私は同じを持っているために、私のオブジェクトの注釈に確認する必要がありますどのような変化を
GET people/_search 
{ 
    "query": { 
    "term": { 
     "child.code": "ABC123" 
    } 
    } 
} 

子供の人にフィールドオプションを適用しますか?私は実際には分析されていないいくつかのフィールドといくつかのレベルの深さを持っています。

+0

'curl -XGET localhost:9200/people'で得られるマッピングを表示できますか? – Val

+0

この情報を含めるために私の質問を編集しました。 – user55295

答えて

1

Automapping in NEST does not recurse further than the top level by defaultしたがって、Personの子プロパティはオブジェクトとしてマッピングされ、動的マッピングとフィールド型推論によってフィールドが作成されますドキュメントにインデックスを付けると、マッピングのchildに表示されます。

NESTは、再帰的に我々は今idcodeは、子オブジェクトにマッピングされます、次のマッピング

{ 
    "properties": { 
    "id": { 
     "type": "integer" 
    }, 
    "code": { 
     "type": "string", 
     "index": "not_analyzed" 
    }, 
    "child": { 
     "properties": { 
     "id": { 
      "type": "integer" 
     }, 
     "code": { 
      "type": "string", 
      "index": "not_analyzed" 
     }, 
     "child": { 
      "properties": {}, 
      "type": "object" 
     } 
     }, 
     "type": "object" 
    } 
    } 
} 

になりますどの.AutoMap(int)

client.Map<Person>(m => m.AutoMap(1)); 

に奥行きパラメータを渡すことで型をマップすることができます予想されるフィールドマッピング設定。 childフィールドはchildになり、objectとしてマップされます。

あなたは深さがしか1になることがわかっている場合は、我々は流暢なマッピング

client.Map<Person>(m => m 
    .AutoMap() 
    .Properties(p => p 
     .Object<Person>(o => o 
      .Name(n => n.child) 
      .Properties(pp => pp 
       .Number(n => n 
        .Name(nn => nn.Id) 
        .Type(NumberType.Integer) 
       ) 
       .String(s => s 
        .Name(n => n.Code) 
        .NotAnalyzed() 
       ) 
      ) 
     ) 
    ) 
); 
を使用することにより、トップレベルの childchildフィールドをしたくない場合は、我々は少しのマッピングを整理することができます

{ 
    "properties": { 
    "id": { 
     "type": "integer" 
    }, 
    "code": { 
     "type": "string", 
     "index": "not_analyzed" 
    }, 
    "child": { 
     "type": "object", 
     "properties": { 
     "id": { 
      "type": "integer" 
     }, 
     "code": { 
      "type": "string", 
      "index": "not_analyzed" 
     } 
     } 
    } 
    } 
} 
関連する問題