How to match multiple should clauses?

Hello,

I'm looking for a way of matching multiple should cases. To explain this better, lets use this example:

"query": {
    "bool": {
        "must": [ ... ]
        "should": [
            {
                "terms" : {
                    "fieldValues" : [1,5,9]
                 }
            },
            {
                "terms" : {
                    "fieldValues" : [2,4,8]
                 }
            }
         ]
    }
}

With this approach, the should part of the query matches:

1 OR 5 OR 9 OR 2 OR 4 OR 8

BUT I need the query to match:

(1 OR 5 OR 9) AND (2 OR 4 OR 8)

How does one achieve this?

Hi.

Change the should to must. Your terms queries are an OR of their array contents already

I've tested this before, even re-tried now to make sure I wasn't making a mistake, but if terms with an array of values is under a must filter, it doesn't match anything at all. Any ideas?

Can you supply a reproduction I can run in Kibana dev tools? Something like this (which works OK):

DELETE test
POST test/_doc/1
{
  "values":["a","e","i","o","u", "x","y","z"]
}
GET test/_search
{
  "query": {
	"bool":{
	  "must":[{
		"terms":{
		  "values":["a", "d"]
		}
	  },{
		"terms":{
		  "values":["w", "x"]
		}
	  }]
	}
  }
}

Might be the weird use-case I'm having here.

If you read the other post I made [Theoretical] How does query filtering upon nested aggregation work?, basically the third question might be the issue here..

  • Does this part of the query:

           "terms": {
             "nested_aggregation": [4, 8]
           }
    

    filter out the values from the documents themselves or aggregations buckets?

Ps: If this still doesn't make sense, I'll try creating a reproduction of the problem so you can try running it.

Your use of terminology is confusing.
Query clauses operate on values in individual documents in individual shards.
Aggregations are summaries of many documents held on many shards.

The former filters the set of documents summarised by the latter.

That sounds like it would be useful. As trimmed-down as possible please (so only has the fields of interest and the minimum number of docs).

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