Ask Your Question
3

How to create a must-exist query in Elasticsearch?

asked 2023-03-11 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-08-23 14:00:00 +0000

huitzilopochtli gravatar image

To create a must-exist query in Elasticsearch, you can use the exists query. This query matches documents where a specific field exists, regardless of its value. Here's an example:

{
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "name"
          }
        }
      ]
    }
  }
}

This query will return all documents that have a non-null value for the "name" field. If you want to include additional query clauses, you can add them to the "must" array.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-03-11 11:00:00 +0000

Seen: 16 times

Last updated: Aug 23 '21