Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use "wildcard" or "regexp" in terms query for nested objects/arrays

I am trying to search the documents using terms filter. I have an array of objects which in turn has a string and an array element. For example:

{
  "shop" : {
    "name" : "bay avenue store",
    "brands": [
       {
         "name" : "coca-cola",
         "items" : ["diet coke", "fanta", "coke-zero"]
        },
       {
         "name" : "pepsi",
         "items" : ["extra zero", "mountain dew"]
        } 
     ]
  }
}

How do I use wildcard inside the "items". I am trying something like:

{
  "query": { 
    "nested" : {
      "path" : "brands",
      "query" : { 
        "match" : {
          {"brands.items": ["*zero"]}
        }
      }
    }
  } 
}

Is this possible? Please suggest me with a solution.

like image 212
Mrinal Deo Avatar asked Oct 19 '25 14:10

Mrinal Deo


1 Answers

Never mind, Found the solution after few hits and trails. Here goes..

"query": {
  "nested": {
    "path":"brands ",
    "query":{
      "wildcard":{
        "brands.items":{
          "value":"*zero*"
        }
      }
    }
  }
}
like image 164
Mrinal Deo Avatar answered Oct 22 '25 04:10

Mrinal Deo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!