小编Joã*_*ves的帖子

突出显示ElasticSearch自动完成功能

我有以下数据要在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)

指数分析

  • 在单词边界上拆分文本.
  • 删除pontuation.
  • 小写字母
  • Edge NGrams每个令牌

因此倒置指数看起来像:

在此输入图像描述

这就是我为名称字段定义映射的方式:

{
    "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)

elasticsearch

5
推荐指数
1
解决办法
1195
查看次数

标签 统计

elasticsearch ×1