0

i am trying to filter my result using nested filter but i am getting incorrect result

here is my mapping info

{
  "stock" : {
    "mappings" : {
      "clip" : {
        "properties" : {
          "description" : {
            "type" : "string"
          },
          "keywords" : {
            "type" : "nested",
            "properties" : {
              "category" : {
                "type" : "string"
              },
              "tags" : {
                "type" : "string",
                "index_name" : "tag"
              }
            }
          },
          "tags" : {
            "type" : "string",
            "index_name" : "tag"
          },
          "title" : {
            "type" : "string"
          }
        }
      }
    }
  }
}

clip document data

{
      "_index" : "stock",
      "_type" : "clip",
      "_id" : "AUnsTOBBpafrKleQN284",
      "_score" : 1.0,
      "_source":{
   "title": "journey to forest",
   "description": "this clip contain information about the animals",
   "tags": ["birls", "wild", "animals", "roar", "forest"],
   "keywords": [
          {
             "tags": ["spring","summer","autumn"],
             "category": "Weather"
          },
          {
             "tags": ["Cloudy","Stormy"],
             "category": "Season"
          },
          {
             "tags": ["Exterior","Interior"],
             "category": "Setting"
          }
       ]
  }

i am trying to filter tags inside nested field 'keywords' here is my query

{
   "query": {
      "filtered": {
         "query": {
            "match_all": {}
         },
         "filter": {
             "nested": {
                 "path": "keywords",
                     "filter": {
                         "bool": {
                             "must": [
                                 {
                                    "terms": { "tags": ["autumn", "summer"] }
                                 }
                         ]
                     }
                 }
             }

         }
      }
   }
}

i am getting no result why ? what's wrong with my query or schema please help

1 Answer 1

1

The above query is syntactically incorrect . You need to provide the full path to tags from root keywords in the term query i.e.keywords.tags

{
   "query": {
      "filtered": {
         "query": {
            "match_all": {}
         },
         "filter": {
             "nested": {
                 "path": "keywords",
                     "filter": {
                         "bool": {
                             "must": [
                                 {
                                    "terms": { "keywords.tags": ["autumn", "summer"] }
                                 }
                         ]
                     }
                 }
             }

         }
      }
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.