Is it possible to return only hits with certain named query in matched_queries array if that query hitted at least one time?

Is it possible to make a search with multiple named queries (let's say named q1_important,q2,q3 etc and all are in bool query's should array) and if there is at least one hit for exactly q1_important query, then return only hits that necessarily contain q1_important in matched_queries array?
I'd like to not make additional unnecessary searches to elasticsearch but it also can't be solved in any good manner in the app's side logic without refactoring.
Example:

  "query": {
    "bool": {
      "must": [],
      "must_not": [],
      "should": [
        {
          "multi_match": {
            "query": "some_text",
            "fields": [
              "brand.NAME",
              "brand.PROP"
            ],
            "type": "best_fields",
            "_name": "q1_important"
          }
        },
        {
          "multi_match": {
            "query": "some_other_text",
            "fields": [
              "detail_text",
              "preview_text"
            ],
            "type": "best_fields",
            "_name": "q2"
          },
        {
          "multi_match": {
            "query": "some_3rd_text",
            "fields": [
              "detail_text",
              "preview_text"
            ],
            "type": "best_fields",
            "_name": "q3"
          }
        }
      ]
    }
  },
  "from": 0,
  "size": 10,
  "sort": [],
  "aggs": {}
}

So if there is at least one hit with q1_important in matched_queries then I want to get only results with matched_queries containing q1_important (like ["q1_important"] or ["q1_important", "q2"] or ["q1_important", "q2", "q3"] etc. and no results like ["q2"], ["q2", "q3"])
else
get all other variants with q2, q3.
Thanks in advance for any help!

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