Hey, guys.
I'm planning a new feature and I would like to know what performs better.
Explaining a bit the scenario:
I have two different filters to be executed and generate different aggregations.
I can either:
- Have a single search with no query filters and two filter aggregations that will split the data and perform inner aggregations.
- Have two different searches, each with its query filter and aggregation to generate results.
Example:
Suppose that I have the following structure:
PUT /x
PUT /x/x/_mapping
{
"properties": {
"x":{
"type": "integer"
}
}
}
PUT /x/x/1
{
"x": 1
}
PUT /x/x/2
{
"x": 2
}
PUT /x/x/3
{
"x": 3
}
I could do:
GET /x/_search
{
"size": 0,
"aggs": {
"f1": {
"filter": {
"range": {
"x": {
"gt": 2
}
}
},
"aggs": {
"max": {
"max": {
"field": "x"
}
}
}
},
"f2": {
"filter": {
"range": {
"x": {
"lt": 2
}
}
},
"aggs": {
"max": {
"max": {
"field": "x"
}
}
}
}
}
}
Or two different searches:
GET /x/_search
{
"query": {
"range": {
"x": {
"gt": 2
}
}
},
"size": 0,
"aggs": {
"max": {
"max": {
"field": "x"
}
}
}
}
GET /x/_search
{
"query": {
"range": {
"x": {
"lt": 2
}
}
},
"size": 0,
"aggs": {
"max": {
"max": {
"field": "x"
}
}
}
}
Considering a large data universe and complex filters, which one would perform better?