0
votes

I'm trying to find a way to search in a same array.

Example Dataset

"_id":"23424232",
"vehicule":[
  "tags":['kawasaki','suzuki','ducati'],
  "tags":['opel','mercedes','ford']
]

if i search for someone with "kawasaki" and "opel" in the same tags array i'm expecting to have 0 hits but elastic found the customer

Query

"query": {
    "bool": {
      "must": [
        { "term": { "vehicule.tags" : "kawasaki"}},
        { "term": { "vehicule.tags" : "opel"}}
      ]
    }
  }

Mapping

"vehicule": {
              "include_in_parent": true,
              "type": "nested",
              "properties": {
                "tags":{
                  "type":"string",
                  "analyzer":"code_tokenizer"
                },

I think it's because for elastic tags is flat and i would like to avoid that. How can i do that ?

"tags":['kawasaki','suzuki','ducati','opel','mercedes','ford']

1

1 Answers

0
votes

i found the solution for me.

{
   "query": {
      "nested": {
         "path": "vehicule.tags",
         "query": {
            "bool": {
               "must": [
                  {
                     "term": {
                        "vehicule.tags": "suzuki"
                     }
                  },
                  {
                     "term": {
                        "vehicule.tags": "opel"
                     }
                  }
               ]
            }
         }
      }
   }
}

and for that query elastic found 0 customer :)