Elasticsearch multi should query with multi minimum_should_match

I need to solve a problem with SHOULD conditions which makes groups and this groups should be separately evaluated according minimum should match. So no only one group with should condition but more separated groups of should conditions.

Imagine conditions like A1, A2, A3 and B1 B2 B3. Simple should query looks like:

{
   "query": {
      "bool": {
         "should": [
            { A1 },
            { A2 },
            { A3 },
            { B1 },
            { B2 },
            { B3 },
         ],
         "minimum_should_match" : 1
      }
   }
}

BUT I need to evaluate minimum_should_match on every groups. One for A group and second for B group. Something like (this is an idea not a valid code):

{
   "query": {
      "bool": {
         "should": [
            { A1 },
            { A2 },
            { A3 },
         ],
         "minimum_should_match" : 1,
         "should": [
            { B1 },
            { B2 },
            { B3 },
         ],
         "minimum_should_match" : 1
      }
   }
}

As you can see I need bool result for each of should groups to be TRUE. Is it possible to do it in ElasticSearch 6? Thanks.

Solution looks like:

{
   "query": {
      "bool": {
         "must: [
             {
                "bool": {
                    "should": [
                        { A1 },
                        { A2 },
                        { A3 },
                    ],
                    "minimum_should_match" : 1
                }
             },
             {
                "bool": {
                    "should": [
                        { B1 },
                        { B2 },
                        { B3 },
                    ],
                    "minimum_should_match" : 1
                }
             }
         ]
      }
   }
}

Thanks to glenacota from https://stackoverflow.com/questions/59893320/elasticsearch-multi-should-query-with-multi-minimum-should-match/59894108#59894108

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