在elasticsearch 中输入查询条件,一般会匹配到很多结果,是因为analyzer的存在,
参考:
So when our term
filter looks for the exact value XHDK-A-1293-#fJ3
, it doesn’t find anything, because that token does not exist in our inverted index. Instead, there are the four tokens listed previously.
Obviously, this is not what we want to happen when dealing with identification codes, or any kind of precise enumeration.
Each element in the result represents a single term:
{ "tokens": [ { "token": "text", "start_offset": 0, "end_offset": 4, "type": "<ALPHANUM>", "position": 1 }, { "token": "to", "start_offset": 5, "end_offset": 7, "type": "<ALPHANUM>", "position": 2 }, { "token": "analyze", "start_offset": 8, "end_offset": 15, "type": "<ALPHANUM>", "position": 3 } ] }
必须要将字段设置为not_analyzed 才可以,如下:
DELETE /my_store PUT /my_store { "mappings" : { "products" : { "properties" : { "productID" : { "type" : "string", "index" : "not_analyzed" } } } } }
转自:
https://www.elastic.co/guide/en/elasticsearch/guide/current/_finding_exact_values.html