POST articles/_bulk
{"index":{}}
{"body":"lucene is very cool"}
{"index":{}}
{"body":"Elasticsearch builds on top of lucene"}
{"index":{}}
{"body":"Elasticsearch rocks"}
{"index":{}}
{"body":"elastic is the company behind ELK stack"}
{"index":{}}
{"body":"ELK stack rocks"}
{"index":{}}
{"body":"elasticsearch is rock solid"}
POST /articles/_search
{
"query": {
"match": {
"body": "lucen rock"
}
},
"suggest": {
"term-suggestion": {
"text": "lucen rock",
"term": {
"suggest_mode" : "popula",
"field": "body"
}
}
}
}
suggest_mode 有三个值: missing 只有上下文不出现term,才会返回纠正词, Popular 推荐出现评率更加高的词, Always 无论是否存在都会推荐
POST /articles/_search
{
"suggest": {
"my-suggestion": {
"text": "lucne and elasticsear rock hello world",
"phrase": {
"field": "body",
"max_errors":"2",
"confidence":2,
"direct_generator" : [
{
"field" : "body",
"suggest_mode":"always"
}],
"highlight":{
"pre_tag":"<em>",
"post_tag":"</em>"
}
}
}
}
}
max_errors: 最多可以拼错的Terms个数, Confidence : 限制返回数, 默认为1