2017-01-23 11 views
4

正確に一致するようにcopy_toが正しく機能していますが、部分一致で正しく設定することができません。以下は、私のマッピング/設定と、期待された結果と実際の結果との照会です。弾性検索|部分検索でcopy_to

設定:

{ 
    "test": { 
     "settings": { 
     "index": { 
      "analysis": { 
       "filter": { 
        "ngram_filter": { 
        "type": "edge_ngram", 
        "min_gram": "1", 
        "max_gram": "15" 
        } 
       }, 
       "analyzer": { 
        "ngram_analyzer": { 
        "filter": [ 
         "lowercase", 
         "ngram_filter" 
        ], 
        "type": "custom", 
        "tokenizer": "standard" 
        } 
       } 
      }, 
      "number_of_shards": "1", 
      "number_of_replicas": "1", 
      } 
     } 
    } 
} 

マッピング:

POST /test/_mapping/name 
{ 
    "name": { 
     "properties": { 
     "vital": { 
      "properties": { 
       "first": { 
        "type": "string", 
        "copy_to": "full_name", 
        "term_vector": "yes", 
        "analyzer": "ngram_analyzer", 
        "search_analyzer": "standard" 
       }, 
       "last": { 
        "type": "string", 
        "copy_to": "full_name", 
        "term_vector": "yes", 
        "analyzer": "ngram_analyzer", 
        "search_analyzer": "standard" 
       }, 
       "full_name": { 
        "type": "string", 
        "term_vector": "yes", 
        "analyzer": "ngram_analyzer", 
        "search_analyzer": "standard" 
       } 
      } 
     } 
     } 
    } 
} 

POST:

POST /test/name 
{ 
    "vital": { 
     "first": "Tom", 
     "last": "Doe" 
    } 
} 

今、私が検索を行うとき...

GET /test/name/_search 
{ 
    "query": { 
    "match": { 
     "full_name": { 
     "query": "Tom Doe", 
     "operator": "and" 
     } 
    } 
    } 
} 

...私は結果を返す! Hurrraaaayが、私は、検索をすれば....

GET /test/name/_search 
{ 
    "query": { 
    "match": { 
     "full_name": { 
     "query": "Tom Do", 
     "operator": "and" 
     } 
    } 
    } 
} 

...私は戻って何の結果を得ていない:(私もFULL_NAMEのために働く部分一致検索をしたいと思います。他にはない、私が起因して成功したことだと

答えて

3

あなたはあなたのマッピングに少し間違いがあります、あなたは、 (GET testを実行すると、マッピングに新しいフィールドが表示されます)full_nameだけでなく、vital.full_nameフィールドにstと姓を入力します。そうでなければ、full_nameという新しい文字列フィールドが作成されます):

POST /test/_mapping/name 
{ 
    "name": { 
     "properties": { 
     "vital": { 
      "properties": { 
       "first": { 
        "type": "string", 
        "copy_to": "vital.full_name",  <--- fix this 
        "term_vector": "yes", 
        "analyzer": "ngram_analyzer", 
        "search_analyzer": "standard" 
       }, 
       "last": { 
        "type": "string", 
        "copy_to": "vital.full_name",  <--- fix this 
        "term_vector": "yes", 
        "analyzer": "ngram_analyzer", 
        "search_analyzer": "standard" 
       }, 
       "full_name": { 
        "type": "string", 
        "term_vector": "yes", 
        "analyzer": "ngram_analyzer", 
        "search_analyzer": "standard" 
       } 
      } 
     } 
     } 
    } 
} 

そして、このようなあなたのクエリを修正する:あなたが期待するよう

POST /test/name/_search 
{ 
    "query": { 
    "match": { 
     "vital.full_name": {   <-- fix this 
     "query": "Tom Doe", 
     "operator": "and" 
     } 
    } 
    } 
} 

POST /test/name/_search 
{ 
    "query": { 
    "match": { 
     "vital.full_name": {   <-- fix this 
     "query": "Tom Do", 
     "operator": "and" 
     } 
    } 
    } 
} 

の両方が動作します。

+0

これ以上必要なものはありますか? – Val

+0

いいえ、その素晴らしい! – emarel