简体   繁体   中英

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. 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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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