Elastic Search Slow Response time range filter query

Hi Everyone,
We a have a use case where we have added a new float field to our Elasticsearch index. The structure of the field is:

class Foo {
	Float x
	Float y
}

This is our filter query which uses the above field:

{
    "from": 0,
    "size": 5,
    "query": {
        "bool": {
            "must": {
                "match_all": {
                    "boost": 1
                }
            },
            "filter": [{
                "range": {
                    "foo.x": {
                        "gte": 3,
                        "lte": 5
                    }
                }
            }]
        }
    }
}

The response time for this query is about 500ms.

However we have another field in the index similar to the above:

class Bar {
	Float a
	Float b
}

Corresponding filter query for the same:

{
    "from": 0,
    "size": 5,
    "query": {
        "bool": {
            "must": {
                "match_all": {
                    "boost": 1
                }
            },
            "filter": [{
                "range": {
                    "foo.x": {
                        "gte": 3,
                        "lte": 5
                    }
                }
            }]
        }
    }
}

The response time for this field when tried with the above filter query is less than 50ms.
Our index size is roughly 100 million documents.

What I have tried so far:

  1. Forcing merge the segments to see if query / node cache improves the latency of the first filter query.
  2. Changed the datatype to float_range and then use it in the range query.

Both these approaches didn't seem to help improve the latency.

Another approach which I tried is to disable the fetch phase of Elastic Search Query by setting the request parameter _source=false in the elastic endpoint. This made the first query very fast (less than 30ms) but unfortunately no metadata were returned. Even without disabling the fetch phase (_source parameter) we returned only 2 or 3 fields in the source.

As such can someone please provide insights as why there could be a difference in the response times for both these filters.

One difference between the two fields is that the first field (Foo) is present in too few documents (in magnitude of hundreds) as compared to the second field (Bar) which is present in the magnitude of ten thousand

That's not an Elasticsearch mapping/field structure, it'd be good if you could share the direct mapping of the fields you are referring to.

Sorry, I should have shared the json document structure. Here it is:

{
    "elastic_index_name": {
        "mappings": {
            "properties": {
                "foo": {
                    "properties": {
                        "x": {
                            "type": "float"
                        },
                        "y": {
                            "type": "float"
                        }
                    }
                },
                "bar": {
                    "properties": {
                        "a": {
                            "type": "float"
                        },
                        "b": {
                            "type": "float"
                        }
                    }
                }
            }
        }
    }
}

Regarding disabling the fetch phase, if I query the below endpoint with the query above the results are very fast but I only get the ids.:

https://<elastic_endpoint>/elastic_index_name/_search?_source=false

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