【发布时间】:2015-11-12 16:45:52
【问题描述】:
我正在使用弹性搜索来查询具有模糊匹配的索引。我正在使用 min_gram 长度为 3 的 edge-ngram 分词器。
但是,对于仅包含 1 或 2 个字符的查询,这不会返回任何内容。是否可以仅匹配 1 或 2 个字符的完全匹配,但使用 edge-ngram 进行具有三个或更多字符的查询?
这是我当前的弹性搜索索引映射:
curl -XPUT 'http://localhost:9200/person' -d '{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 3,
"max_gram": 20
}
},
"analyzer": {
"default": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
}
}'
要查询这个索引,请求如下:
curl -XPOST 'localhost:9200/person/type/_search' -d '{
"query": {
"match": {
"_all": "Tim”
}
}
}'
产生大量结果,但是像这样的请求
curl -XPOST 'localhost:9200/person/type/_search' -d '{
"query": {
"match": {
"_all": "Ti”
}
}
}'
给出一个空集。理想情况下,如果索引中有名为 Tim 的人,则第二个请求会返回一些结果。
【问题讨论】:
标签: elasticsearch n-gram