我試圖使用ElasticSearch實現地址自動完成。ElasticSearch:精確度低於部分匹配
想,我有三個字段,我想執行搜索:
{
"address_name": "George st.",
"number": "1",
"city_name": "London"
}
據this article,我已經配置了我的索引和類型是這樣的:
{
"settings": {
"analysis": {
"filter": {
"nGram_filter": {
"type": "nGram",
"min_gram": 1,
"max_gram": 20,
"token_chars": [
"letter",
"digit",
"punctuation",
"symbol"
]
}
},
"analyzer": {
"nGram_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding",
"nGram_filter"
]
},
"whitespace_analyzer": {
"type": "custom",
"tokenizer": "whitespace",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
},
"mappings": {
"address": {
"_all": {
"analyzer": "nGram_analyzer",
"search_analyzer": "whitespace_analyzer"
},
"properties": {
"address_name": {
"type": "string"
},
"number": {
"type": "string",
"boost": 2
},
"city_name": {
"type": "string"
},
"local": {
"type": "integer",
"include_in_all": false,
"index": "no"
},
"place_id": {
"type": "integer",
"include_in_all": false,
"index": "no"
},
"has_number": {
"type": "integer",
"include_in_all": false,
"index": "no"
}
}
}
}
}
全部搜索查詢:
{
"size": 100,
"query": {
"match": {
"_all": {
"query": "George st. 1 London",
"operator": "and"
}
}
}
}
當我通過查詢George st. 1 London
,ElasticSearch首先返回我George st. 19 London
,George st. 17 London
等,但完全匹配George st. 1 London
僅返回第X個位置,並且得分最低。
我試圖通過將explain
查詢添加到搜索URL的末尾來理解它爲什麼會發生,但它沒有幫助。
有什麼辦法可以解決這個問題嗎?
謝謝。
你還可以分享你發送的查詢嗎? – Val
'George st。 1倫敦'。謝謝。 –
我的意思是你使用什麼查詢DSL?你能展示你如何發送你的查詢? – Val