1. 什麼是搜索建議?
2. ES實現原理
3. 對應API,Term& Phrase Suggester
TermSuggester
3種Suggestion Mode
一個排序
首字母限制
4. 例子
# 刪除之前的Index
DELETE articles
# 插入2個測試數據
POST articles/_bulk
{ "index" : { } }
{ "body": "elasticsearch is good"}
{ "index" : { } }
{ "body": "elasticsearch is ok"}
POST /articles/_search
{
"size": 1,
"query": {
"match": {
"body": "elasticseach"
}
},
"suggest": {
"term-suggestion": {
"text": "elasticseach",
"term": {
"suggest_mode": "missing",
"field": "body"
}
}
}
}
對應結果
{
"took" : 13,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"suggest" : {
"term-suggestion" : [
{
"text" : "elasticseach",
"offset" : 0,
"length" : 12,
"options" : [
{
"text" : "elasticsearch",
"score" : 0.9166667,
"freq" : 2
}
]
}
]
}
}
option部分就是對應的推薦詞