Hi everyone,
We are using ElasticSearch Nest client to build an API with Dot Net Core to run queries towards an ElasticSearch cluster. Most of the times, we run the same type of query with a filter that's provided as part of the API call, so we have wrapped it into a method like this:
var stopWatch = new Stopwatch(); // stopwatch added to investigate the issue
stopWatch.Start();
var searchRequest = new SearchRequest<Price>
{
Size = 0,
Query = new BoolQuery()
{
Must = _filterTermQueries_
},
Aggregations = aggrs
};
var results = indexClient.Search<Price>(searchRequest);
timeTracking.Enqueue($"Search done - {stopwatch.ElapsedMilliseconds} - {results.Took}");
Most of the time, the stopwatch time is +-50 ms more than the results.Took time, understandable due to serialization and deserialization of the request/response.
The problem is that, every once in a while, the difference between the two is up to 3 seconds, hence the API takes more than 3 seconds to answer even though ElasticSearch indexes only spent milliseconds finding the data.
Note this happens with load (via JMeterLoadTest) and without load (single call via postman).
I've read in this discussion that: "Bear in mind that the first query to Elasticsearch from NEST will be much slower because the client caches a lot of delegates, compiled expressions and json serialization properties on this first call."
Hence I question myself:
- For how long are those things cached? Could it be that those caches are evicted every once in a while and we have to pay this price again?
- Is there any way to gather extra information about them at runtime?
Any help would be appreciated, thanks!