Must_not not working as expected, elasticsearch5.5


(Shruti Mansinghka) #1

I have a nested type-> documents inside applications. I want to retrieve the applications which do not contain the documents with document_type 6.

{
"query": {
"bool": {
"must_not": [
{
"nested": {
"path": "documents",
"query": {
"bool": {
"must": [
{
"term": {
"document_type": 6
}
}
]
}
}
}
}
]
}
}
}

This gives applications with document_type 6 as well. Not sure if there's something wrong with the query.


(Abdon Pijpelink) #2

You need to provide the full path to the nested field: documents.document_type. Your query becomes:

{
  "query": {
    "bool": {
      "must_not": [
        {
          "nested": {
            "path": "documents",
            "query": {
              "term": {
                "documents.document_type": 6
              }
            }
          }
        }
      ]
    }
  }
}

(system) #3

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