Multiple weighted boolean queries within one search

I would like to have multiple weighted boolean queries within one search. I'm using the ElasticSearch Python client.

The use case would be for example as following:

Query 1 AND Query 2 --> Weight 3.0
Query 1 OR Query 2 --> Weight 2.0

I would then like to have this search outputting only one result, so those two searches combined into one ranking result.

Currently, I have something like this (I left out some cases to make it more simple as there are originally 5 'big cases')

payload={
      "size": 1000,
      "query": {
        "bool": {
          "should": [{
            "bool": {
              "must": [{
                  "bool": {
                    "should": [An array of query_string objects]
                  }
                },
                {
                  "bool": {
                    "should": [An array of query_string objects]
                  }
                },
                {
                  "bool": {
                    "should": [An array of query_string objects]
                  }
                }
              ],
              "boost": 9.0
            },
              "bool": {
              "should": [{
                  "bool": {
                    "should": [An array of query_string objects]
                  }
                },
                {
                  "bool": {
                    "should": [An array of query_string objects]
                  }
                },
                {
                  "bool": {
                    "should": [An array of query_string objects]
                  }
                }
              ],
              "boost": 4.5
            }
          }]
        }
      }
    }

The first query within the outer should is an AND-AND, the second one is an OR-OR.

I do however notice that if I swap the boost 9.0 query with the boost 4.5 query, my results change. This makes me think that there's something wrong with this way of doing it, possibly only taking into account the last query?

Could anyone tell me how to do this in a proper way, and if this is even possible? Thank you in advance!

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