1

I have a nested data mapping in a document and I want to query if a nested field does not exist.

This elastic query is working but what will be the elastic DSL representation on this query?

GET products/_search

{
  "query": {
    "bool": {
      "must_not": [
        {
          "nested": {
            "path": "attributes",
            "query": {
              "exists": {
                "field": "attributes.value"
              }
            }
          }
        }
      ]
    }
  }
}

I have tried with this, but it's not working

ProductDocument.search().query(
    "nested",
    path="attributes",
    query=(~Q('exists', field='attributes.value'))
)

This DSL query represent as and it's wrong I think

{
  "query": {
    "nested": {
      "path": "attributes",
      "query": {
        "bool": {
          "must_not": [{
            "exists": {
              "field": "attributes.value"
            }
          }]
        }
      }
    }
  }
}

N.B: I am using elastic 6.7, elasticsearch-dsl 6.4.2

1 Answer 1

3

Finally, I find out the query

ProductDocument.search().query(~Q(
    "nested",
    path="attributes",
    query=Q("exists", field='attributes.value'))
))
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.