我有以下数据要在ElasticSearch上编制索引.
我想实现自动完成功能,并突出显示特定文档与查询匹配的原因.
这是我的索引的设置:
{
"settings": {
"number_of_shards": 1,
"analysis": {
"filter": {
"autocomplete_filter": {
"type": "edge_ngram",
"min_gram": 1,
"max_gram": 15
}
},
"analyzer": {
"autocomplete": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"autocomplete_filter"
]
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
指数分析
因此倒置指数看起来像:
这就是我为名称字段定义映射的方式:
{
"index_type": {
"properties": {
"name": {
"type": "string",
"index_analyzer": "autocomplete",
"search_analyzer": "standard"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我查询时:
GET http://localhost:9200/index/type/_search
{
"query": {
"match": {
"name": "soft"
}
},
"highlight": {
"fields" : …Run Code Online (Sandbox Code Playgroud)