我有一个具有以下配置的自定义分析器索引的字段

 "COMPNAYNAME" : {
          "type" : "text",
          "analyzer" : "textAnalyzer"
        }

 "textAnalyzer" : {
              "filter" : [
                "lowercase"
              ],
              "char_filter" : [ ],
              "type" : "custom",
              "tokenizer" : "ngram_tokenizer"
            }

 "tokenizer" : {
            "ngram_tokenizer" : {
              "type" : "ngram",
              "min_gram" : "2",
              "max_gram" : "3"
            }
          }
当我搜索文本“ikea”时,我得到以下结果
查询:
GET company_info_test_1/_search
{
  "query": {
    "match": {
      "COMPNAYNAME": {"query": "ikea"}
    }
  }
}
休假是结果,
1.mikea
2.likeable
3.maaikeart
4.likeables
5.ikea b.v.  <------
6.likeachef
7.ikea breda <------
8.bernikeart
9.ikea duiven
10.mikea media
我希望完全比对的结果应该比其余结果有所提高。
如果我必须同时进行精确匹配和含糊不清的搜索,您能帮我什么是最好的索引方法。
提前致谢。

最佳答案


如@EvaldasBuinauskas所指出的,如果您希望仅从头开始而不是从中间生成标记,则也可以在此处使用edge_ngram tokenizer
添加带有索引数据,映射,搜索查询和结果的工作示例
索引数据:

{ "title": "ikea b.v."}
{ "title" : "mikea" }
{ "title" : "maaikeart"}
索引映射
{
    "settings": {
        "analysis": {
            "analyzer": {
                "my_analyzer": {
                    "tokenizer": "my_tokenizer"
                }
            },
            "tokenizer": {
                "my_tokenizer": {
                    "type": "ngram",
                    "min_gram": 2,
                    "max_gram": 10,
                    "token_chars": [
                        "letter",
                        "digit"
                    ]
                }
            }
        },
        "max_ngram_diff": 50
    },
    "mappings": {
        "properties": {
            "title": {
                "type": "text",
                "analyzer": "my_analyzer",
                "search_analyzer": "standard"
            }
        }
    }
}
搜索查询:
{
    "query": {
        "match" : {
            "title" : "ikea"
        }
    }
}
搜索结果:
"hits": [
            {
                "_index": "normal",
                "_type": "_doc",
                "_id": "4",
                "_score": 0.1499838,    <-- note this
                "_source": {
                    "title": "ikea b.v."
                }
            },
            {
                "_index": "normal",
                "_type": "_doc",
                "_id": "1",
                "_score": 0.13562363,    <-- note this
                "_source": {
                    "title": "mikea"
                }
            },
            {
                "_index": "normal",
                "_type": "_doc",
                "_id": "3",
                "_score": 0.083597526,
                "_source": {
                    "title": "maaikeart"
                }
            }
        ]

关于elasticsearch - Elasticsearch 结果与预期不符,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63917546/

10-17 03:14