Is this a correct query? i need to confirm, can i use multiple must in a single query


(Anuj Shrivastava) #1

I am getting "multiple must" syntex error in DevTools in below query, i want to use multiple must statement
GET logstash-security-*/_search
{
"query": {
"bool": {
"must": {
"bool" : { "should": [
{ "match": { "title": "Elasticsearch" }},
{ "match": { "title": "Solr" }} ] }
},
"must": { "match": { "authors": "clinton gormely" }},
"must_not": { "match": {"authors": "radu gheorge" }}
}
}
}


(Alexander Reelsen) #2

the must key is duplicated. Indenting the JSON in this case would help a lot to make the issue more visible. Take a look at this one (not sure I understood your intent a hundred percent, so handle with care)

GET logstash-security-*/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              { "match": { "title": "Elasticsearch" } },
              { "match": { "title": "Solr" } }
            ]
          }
        },
        { "match": { "authors": "clinton gormely" } }
      ],
      "must_not": {
        "match": { "authors": "radu gheorge" } }
    }
  }
}


(Anuj Shrivastava) #3

Thanks Alex,

i got this query from a blog where 2 must in same query was described, now i came to know that was wrongly mentioned.

I used Nested bool query and it worked.


(system) #4

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