【发布时间】:2019-03-11 01:57:39
【问题描述】:
我在 Elasticsearch 中搜索“Adana”这个词,并希望它排在最前面,因为它是准确的词,但它不是。
取而代之的是“Bilmemne Adana Otel”。
普通查询没有任何好处,所以我尝试了带有“必须”和“应该”的布尔查询。但它也没有改变任何东西。
除此之外,如果我写“Ada”,“Adana”也应该排在第一位。
我们怎样才能让它正常工作?
查询:
curl -X GET "localhost:9200/destinations/_search" -H 'Content-Type:
application/json' -d'
{
"query": {
"match": {
“Name”: {
"query": “Adana”
}
}
}
}
'
结果:
{
"took" : 16,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 3.255435,
"hits" : [
{
"_index" : "destinations",
"_type" : "_doc",
"_id" : "10",
"_score" : 3.255435,
"_source" : {
"name" : "Bilmemne Adana Otel"
}
},
{
"_index" : "destinations",
"_type" : "_doc",
"_id" : "4",
"_score" : 2.8624198,
"_source" : {
"name" : "Adana"
}
},
{
"_index" : "destinations",
"_type" : "_doc",
"_id" : "1",
"_score" : 2.3216834,
"_source" : {
"name" : "Adana Airport Otel - Adana"
}
}
]
}
}
索引:
{
"settings": {
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 15
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"autocomplete_filter"
]
}
}
}
},
"mappings": {
"_doc": {
"properties": {
"name": {
"type": "text",
"analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}
}
【问题讨论】:
标签: elasticsearch search full-text-search