Elasticsearch case带有间隔词的隐性通配符搜索

问题描述 投票:1回答:1

我的索引中包含以下文件字段priorityName的类型为search_as_you_type dataType我的用例就像我想用以下单词搜索文档:---

  1. “ let's”->应该同时给出两个结果
  2. “ DOING”->应该同时给出两个结果
  3. “是您”->应该同时给出两个结果
  4. “ Are You”->应该同时给出两个结果
  5. “您做”(您做不到)->应该同时给出两个结果
  6. “您”->应该同时给出两个结果

6个中只有前5个使用multi_match给我想要的结果我怎么有第6个用例,其中我们可以有不完整的单词而不是以第一个字符开头。

        "_index": "priority",
        "_type": "_doc",
        "_id": "vaCI_HAB31AaC-t5TO9H",
        "_score": 1,
        "_source": { - 
          "priorityName": "What are you doing along Let's Go out"
        }
      },
      { - 
        "_index": "priority",
        "_type": "_doc",
        "_id": "vqCQ_HAB31AaC-t5wO8m",
        "_score": 1,
        "_source": { - 
          "priorityName": "what are you doing along let's go for shopping"
        }
      }
    ]
  }```
elasticsearch space case-insensitive
1个回答
0
投票
对于上一次搜索re you,您需要infix tokens,默认情况下,它不包含在search_as_you_type数据类型中。我建议您创建一个自定义分析器,该分析器将创建中缀令牌并允许您匹配所有6个查询。

我已经创建了一个自定义分析器,并使用您的示例文档对其进行了测试,所有6个查询都给出了两个示例结果。

索引映射

POST / infix-index

{ "settings": { "max_ngram_diff": 50, "analysis": { "filter": { "autocomplete_filter": { "type": "ngram", "min_gram": 1, "max_gram": 8 } }, "analyzer": { "autocomplete_analyzer": { "type": "custom", "tokenizer": "whitespace", "filter": [ "lowercase", "autocomplete_filter" ] }, "lowercase_analyzer": { "type": "custom", "tokenizer": "whitespace", "filter": [ "lowercase" ] } } } }, "mappings": { "properties": { "priorityName": { "type": "text", "analyzer": "autocomplete_analyzer", "search_analyzer": "standard" --> not this } } } }

为示例文档建立索引

{ "priorityName" : "What are you doing along Let's Go out" } { "priorityName" : "what are you doing along let's go for shopping" }

搜索最后一个re you的查询

{ "query": { "match" : { "priorityName" : "re you" } } }

和结果

"hits": [ { "_index": "ngram", "_type": "_doc", "_id": "1", "_score": 1.4652853, "_source": { "priorityName": "What are you doing along Let's Go out" } }, { "_index": "ngram", "_type": "_doc", "_id": "2", "_score": 1.4509768, "_source": { "priorityName": "what are you doing along let's go for shopping" } }

[其他查询也向我返回了两个文档,但不包括它们以缩短此答案的长度。]
© www.soinside.com 2019 - 2024. All rights reserved.