Bool + range query performance

Hi,
I'm trying to execute a rather complicated nested bool query:
((string match and range) OR (string match and range)) AND((string match and range) OR (string match and range)) AND ...

and I see that the range query has a tremendous effect on performance (~400ms per range).
Been making an effort to run this under nested filter but haven't been able to build a valid query.

Currently the query looks like this:

{
"size": 0,
"query": {
"bool": {
"must": [
{
"nested": {
"path": "obj1",
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"match": {
"var": "example4"
}
},
{
"range": {
"absolutePvs": {
"gte": 1
}
}
}
]
}
},
{
"bool": {
"must": [
{
"match": {
"var": "example3"
}
},
{
"range": {
"absolutePvs": {
"gte": 1
}
}
}
]
}
}
]
}
}
}
},
{
"nested": {
"path": "obj2",
"query": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"match": {
"var": "example1"
}
},
{
"range": {
"absolutePvs": {
"gte": 1
}
}
}
]
}
},
{
"bool": {
"must": [
{
"match": {
"var": "example2"
}
},
{
"range": {
"absolutePvs": {
"gte": 1
}
}
}
]
}
}
]
}
}
}
}
]
}
}
}

currently this query takes ~3 seconds to run. When removing the range conditions, the query runs
in ~300ms.
Does anyone know how can I improve this???

Thanks in advanced,
Oren

In case someone else encounters this problem, I found the solution: using filtered query + and filters:

Runs really really fast now :slight_smile:

POST _search
{
"size": 1,
"query": {
"filtered": {
"filter": {
"and": {
"filters": [
{
"nested": {
"path": "obj1",
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"fquery": {
"query": {
"match": {
"var": "example4"
}
},
"_cache": true
}
},
{
"range": {
"Pvs": {
"gte": 1
}
}
}
]
}
},
{
"bool": {
"must": [
{
"fquery": {
"query": {
"match": {
"var": "example3"
}
},
"_cache": true
}
},
{
"range": {
"Pvs": {
"gte": 1
}
}
}
]
}
}
]
}
}
}
}
}
},
{
"nested": {
"path": "obj2",
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"fquery": {
"query": {
"match": {
"var": "example2"
}
},
"_cache": true
}
},
{
"range": {
"Pvs": {
"gte": 1
}
}
}
]
}
},
{
"bool": {
"must": [
{
"fquery": {
"query": {
"match": {
"var": "example1"
}
},
"_cache": true
}
},
{
"range": {
"Pvs": {
"gte": 1
}
}
}
]
}
}
]
}
}
}
}
}
}
]
}
}
}
}
}