2017-10-27 8 views
0

以下はマッピングとアナライザーの設定です。 「ブック」レコードのインデックスを作成しているとしましょう。書籍レコード(出版社やタグなど)の複数のフィールドは文字列(「ランダムハウス」、「macmillan」など)の配列で、フィールド「名前」は「青」などの単数の文字列です。私のようなクエリを実行した場合このクエリは、エッジngram elasticsearchマッピングに基づいて結果が返されないのはなぜですか?

{ 
    "state": "open", 
    "settings": { 
     "index": { 
     "number_of_shards": "5", 
     "provided_name": "autocomplete_index", 
     "creation_date": "1509080632268", 
     "analysis": { 
      "filter": { 
       "edge_ngram": { 
        "token_chars": [ 
        "letter", 
        "digit" 
        ], 
        "min_gram": "1", 
        "type": "edgeNGram", 
        "max_gram": "15" 
       }, 
       "english_stemmer": { 
        "name": "possessive_english", 
        "type": "stemmer" 
       } 
      }, 
      "analyzer": { 
       "keyword_analyzer": { 
        "filter": [ 
        "lowercase", 
        "english_stemmer" 
        ], 
        "type": "custom", 
        "tokenizer": "standard" 
       }, 
       "autocomplete_analyzer": { 
        "filter": [ 
        "lowercase", 
        "asciifolding", 
        "english_stemmer", 
        "edge_ngram" 
        ], 
        "type": "custom", 
        "tokenizer": "standard" 
       } 
      } 
     }, 
     "number_of_replicas": "1", 
     "uuid": "SSTzdTNFStaSiIBu-l3q5w", 
     "version": { 
      "created": "5060299" 
     } 
     } 
    }, 
    "mappings": { 
     "autocomplete_mapping": { 
     "properties": { 
      "publishers": { 
       "type": "text", 
       "fields": { 
        "keyword": { 
        "ignore_above": 256, 
        "type": "keyword" 
        } 
       } 
      }, 
      "name": { 
       "type": "text", 
       "fields": { 
        "keyword": { 
        "ignore_above": 256, 
        "type": "keyword" 
        } 
       } 
      }, 
      "tags": { 
       "type": "text", 
       "fields": { 
        "keyword": { 
        "ignore_above": 256, 
        "type": "keyword" 
        } 
       } 
      } 
     } 
     } 
    }, 
    "aliases": [], 
    "primary_terms": { 
     "0": 1, 
     "1": 1, 
     "2": 1, 
     "3": 1, 
     "4": 1 
    }, 
    "in_sync_allocations": { 
     "0": [ 
     "GXwYiYuWQ16wgxCrpXShJQ" 
     ], 
     "1": [ 
     "Do_49lZ4QmyNEYUK_QJfEQ" 
     ], 
     "2": [ 
     "vWZ_PjsLSGSVh130C5EvYQ" 
     ], 
     "3": [ 
     "5CLINaFJQbqVcZLVOsSNWQ" 
     ], 
     "4": [ 
     "hy3JYfmuR7e8fc-anu-heA" 
     ] 
    } 
} 

は:

curl -XGET 'localhost:9200/autocomplete_index/_search?size=5' -d ' 
{ 
"query" : { 
    "multi_match" : { 
     "query": "b", 
     "analyzer": "keyword", 
     "fields": ["_all"] 
    } 
    } 
}' 

私は0結果を得ます。私は、照合フィールドに完全な単語 "青"を入れて一致を得る必要があります。私は「_analyze」を行う際

さらに、私が取得:

curl -XGET 'localhost:9200/products_autocomplete_dev/_analyze?pretty' -H 'Content-Type: application/json' -d' 
{ 
    "analyzer": "autocomplete_analyzer", 
    "field": "name", 
    "text": "b" 
} 
' 

{ 
    "tokens" : [ 
    { 
     "token" : "b", 
     "start_offset" : 0, 
     "end_offset" : 1, 
     "type" : "<ALPHANUM>", 
     "position" : 0 
    } 
    ] 
} 

私は、このような「B」、「BL」、「ブルー」、および「青」のようにトークンを取り戻すことを期待します少なくとも。

{ 
    "_index" : "autocomplete_index", 
    "_type" : "autocomplete_mapping", 
    "_id" : "145", 
    "_version" : 1, 
    "found" : true, 
    "_source" : { 
    "name": "Blue", 
    "publishers" : [ 
     "macmillan", 
     "Penguin" 
    ], 
    "themes" : [ 
     "Butterflies", "Mammals" 
    ] 
    } 
} 

は私が間違って何をやっている:ここで

は、インデックスからのサンプル文書のですか?

答えて

0

このように間違っていることがたくさんあるので、アナライザに関するドキュメントをよくお読みになることをお勧めします。私はこれを示唆している気にしないことを願っています。

まず第一に、あなたはアナライザをテストしたい場合は、だけでなくテキストのみとアナライザ自体のフィールド名を指定しない:カスタムアナライザを定義した場合

GET /my_index/_analyze?pretty 
{ 
    "analyzer": "autocomplete_analyzer", 
    "text": "blue" 
} 

を、どのようにすべきですElasticsearchは特定のフィールドがそのアナライザを使用していることを知っていますか?アナライザを定義することは、それを使用して特定のフィールドを作成することと同じではありません。だから、:

"name": { 
     "type": "text", 
--> "analyzer": "autocomplete_analyzer", 
     "fields": { 
     "keyword": { 
      "ignore_above": 256, 
      "type": "keyword" 
     } 
     } 
    } 

同じことが_allフィールドのために行く:デフォルトでは、それはstandardアナライザを使用しています、そしてあなたがそれを変更しない限り、それは同じを使用します。

"mappings": { 
    "autocomplete_mapping": { 
     "_all": { 
     "analyzer": "autocomplete_analyzer" 
     }, 
     "properties": { 
     "publishers": { 
      "type": "text", 
      "fields": { 
..... 
関連する問題