您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如果将min_gram设置为1,则在ngram过滤器上突出显示Elasticsearch是很奇怪的

如果将min_gram设置为1,则在ngram过滤器上突出显示Elasticsearch是很奇怪的

您需要检查 并查看是否使用fast-vector-Highlighter。但是,您仍然需要非常小心自己的查询

假设使用ES的新实例0.20.4localhost

以您的示例为基础,让我们添加显式映射。注意我为该code字段设置了两种不同的分析。唯一的区别是"term_vector":"with_positions_offsets"

curl -X PUT localhost:9200/myindex -d '
{
  "settings" : {
    "index":{
      "number_of_replicas":0,
      "number_of_shards":1,
      "analysis":{
        "analyzer":{
          "default":{
            "type":"custom",
            "tokenizer":"keyword",
            "filter":[
              "lowercase",
              "my_ngram"
            ]
          }
        },
        "filter":{
          "my_ngram":{
            "type":"nGram",
            "min_gram":1,
            "max_gram":20
          }
        }
      }
    }
  },
  "mappings" : {
    "product" : {
      "properties" : {
        "code" : {
          "type" : "multi_field",
          "fields" : {
            "code" : {
              "type" : "string",
              "analyzer" : "default",
              "store" : "yes"
            },
            "code.ngram" : {
              "type" : "string",
              "analyzer" : "default",
              "store" : "yes",
              "term_vector":"with_positions_offsets"
            }
          }
        }
      }
    }
  }
}'

索引一些数据。

curl -X POST 'localhost:9200/myindex/product' -d '{
  "code" : "Samsung Galaxy i7500"
}'

curl -X POST 'localhost:9200/myindex/product' -d '{
  "code" : "Samsung Galaxy 5 Europa"
}'

curl -X POST 'localhost:9200/myindex/product' -d '{
  "code" : "Samsung Galaxy Mini"
}'

现在我们可以运行查询了。

其他 2022/1/1 18:15:47 有563人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶