Could query contain multi sub query type in es

Viewed 23

I have following simple code snippet. I want to query the documents that contains value field and also the name is hello,

PUT /lib59/_doc/1
{
  "name": "hello",
  "value":1
}


GET /lib59/_search
{
  "query":{
    "term": {
      "name":"hello"
    },
    "exists": {
      "field": "value"
    }
  }
}

But when I run it, an error occurs, the error message is:

I would ask whether ES supports the query as I wrote above, if not, how could I express my query? Thanks.

1 Answers

You need to combine your query using bool/must clause

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "name": "hello"
          }
        },
        {
          "exists": {
            "field": "value"
          }
        }
      ]
    }
  }
}
Related