Search character ( wild card )

How we use wild card to search in elasticsearch. I try with following queries

"query": {
  "wildcard": {
    "item_name": {
        "value": "*Iko*",
        "boost": 1.0,
        "rewrite": "constant_score"
    }
}

and like this

"match": {
  "item_name": "*Ik"
}

and like this

"regexp": {
  "item_name": "^Iko"
}

data have value

{
              "_index" : "product_detail_info",
              "_type" : "doc",
              "_id" : "1733951907733120138583162807",
              "_score" : 6.0950193,
              "_source" : {
                "image_product_name" : "5dd90d61e82a7.jpg",
                "item_sku" : "SS190773",
                "item_id" : 190773,
                "cat_name" : "T-Shirts",
                "product_id" : 31201,
                "item_name" : "Ikonik Karl Pocket T-Shirt"
              }

and I want to apply same search on more then one fields

thanks

What is the mapping of that field? Is it by any chance mapped as text? If you are using default mappings you could try the keyword sub field.

Yes it is mapped as text

Do you have a keyword sub field you can use instead?

it works. How about searching in multiple fields ?

I recommend reading this: Query string query | Elasticsearch Guide [8.11] | Elastic

Allowing a wildcard at the beginning of a word (eg "*ing" ) is particularly heavy, because all terms in the index need to be examined, just in case they match. Leading wildcards can be disabled by setting allow_leading_wildcard to false .

Although it will be improved in the future, the query you are running will be extremely slow IMO.

1 Like

Agreed. I want to use wildcard in more then one fields.

Use the query string query maybe?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.