简体   繁体   English

弹性搜索中的通配符搜索

[英]wildcard search in elasticsearch

Currently i use below wildcard search for my service,目前我使用以下通配符搜索我的服务,

{
  "query": {
    "bool": {
      "must": [
        {
          "wildcard": {
            "PRODUCT_DESCRIPTION": "\*collaboration\*services\*shiriyara\*"
          }
        }
      ]
    }
  }
}

This returns me expected result.这将返回我预期的结果。 But i am looking for alternative ways to achieve this without using wildcard query, as wildcard takes more time.但是我正在寻找不使用通配符查询的替代方法来实现这一点,因为通配符需要更多时间。

I tried "query_string" on a "standard" analyzed field.我在“标准”分析字段上尝试了“query_string”。 But this returns result if whole word matches.但是如果整个单词匹配,这将返回结果。

          "query_string": {
            "default_field": "PRODUCT_DESCRIPTION",
            "default_operator": "AND",
            "query": "collaboration services shiriyara"
          }

If the string is "collab services shiriyara", it won't give any result, whereas wildcard gives.如果字符串是“collab services shiriyara”,它不会给出任何结果,而通配符给出。

Let me know, if anybody has thoughts.让我知道,如果有人有想法。 Index time changes also fine with me.索引时间变化对我来说也很好。

You could break up your wildcards as follows, which would work for the example you have given:您可以按如下方式分解通配符,这适用于您给出的示例:

GET my_index/_search
{
  "query": {
    "bool": {
      "must": [
        {"wildcard": {"PRODUCT_DESCRIPTION": "collab*"}},
        {"wildcard": {"PRODUCT_DESCRIPTION": "serv*"}},
        {"wildcard": {"PRODUCT_DESCRIPTION": "shiri*"}}
      ]
    }
  }
}

Alternatively, you could look at using ngrams at index time, which would allow matching of character sequences within a word.或者,您可以考虑在索引时使用ngrams ,这将允许匹配单词中的字符序列。

我知道这是一个老问题,但以防万一有人再次遇到它:在 Elasticsearch 7.9 中,引入了一个新的通配符字段类型,用于快速查找字符串值中的模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM