使用Elasticsearch完成建議程序我在返回與單字查詢匹配的多字輸入建議時遇到問題。Elasticsearch完成建議使用多字輸入進行搜索
實施例結構:
PUT /test_index/
{
"mappings": {
"item": {
"properties": {
"test_suggest": {
"type": "completion",
"index_analyzer": "whitespace",
"search_analyzer": "whitespace",
"payloads": false
}
}
}
}
}
PUT /test_index/item/1
{
"test_suggest": {
"input": [
"cat dog",
"elephant"
]
}
}
工作查詢:
POST /test_index/_suggest
{
"test_suggest":{
"text":"cat",
"completion": {
"field" : "test_suggest"
}
}
}
與結果
{
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"test_suggest": [
{
"text": "cat",
"offset": 0,
"length": 3,
"options": [
{
"text": "cat dog",
"score": 1
}
]
}
]
}
失敗查詢:
POST /test_index/_suggest
{
"test_suggest":{
"text":"dog",
"completion": {
"field" : "test_suggest"
}
}
}
與結果
{
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"test_suggest": [
{
"text": "dog",
"offset": 0,
"length": 3,
"options": []
}
]
}
我希望同樣的結果作爲工作的查詢,匹配「貓狗」。任何建議是什麼問題以及如何使失敗的查詢工作?當使用標準分析儀代替空白分析儀時,我會得到相同的結果。我想在上面的例子中給每個輸入字符串使用多個單詞。
搜索+查詢不返回文本和我的情況下,文本可以是三個字段中的任何東西,所以我怎麼能顯示自動完成確切的文本。 –