Full-text search is faster if queries are sent constantly

Please help me understand my case, as I am new to Elasticsearch.
I use Elasticsearch on a single node to make full-text search queries from a Python API.
The problem is that searching time may vary from seconds to tens of seconds between two identical queries.
But when I artificially send constant queries throuth a script to my search method in Python API (which sends a full-text query to Elasticsearch server), the overall search speed increases significantly, and the difference between two identical queries is significally less too.
Which may be the cause of this? May it be the Elasticsearch phenomenon or should I look into performance of other components of a project (like Python API)?

Welcome!

This is indeed something which happens when you are indexing.

If you are not running searches, Elasticsearch does not refresh immediately the index for optimization purpose.

If you are running queries frequently, Elasticsearch adapts itself.

1 Like

@athlonIIx2 , may be you want to optimize your searches using more filters and aggregations instead of must/should/terms/ etc. queries.

1 Like

Yeah but in any case, if the index has not seen search requests for a while, it will have to do a refresh first.

IMO the default behavior is good as it's a good compromise between the speed and the number of segments being created (and the disk IO needed to merge frequently small segments).
But this can be changed with an index settings. See Tune for indexing speed | Elasticsearch Guide [8.6] | Elastic

2 Likes

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