Retrieve each filter response in one result

Hi,

Is it possible to combine three or more filter query with each wished size and get ids of document separately in result?

For example; size parameter in query is 100 and I need to get 10 documents from first of my filter which "my_field": "foo" and 20 documents from second of my filter which "another_field": "bar" etc .

Desired result;

{
...,
"hits" : {
    "total" : {
      "value" : 100,
      "relation" : "eq"
    },
    "hits" : [
      {
        ....,
        "result_one" : {
          "ids" : [1,2,3,4,....] # total count 10 or less
        },
        "result_two" : {
          "ids" : [10,20,30,....] # total count 20 or less
        },
        "result_three" : {
          "ids" : [9, 8, 7,....]
        }
      }
    ]
  }
}

I can achieve this with making 3 _search request to my index but is there any way to make this only one request?

You can use an _msearch request with three queries.

Thank you for advice.

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