How to optimize my ElasticSearch Query

We tried with 2 replicas and we had more errors.

Ok I'll try this. Thanks

… and please keep trying to profile the query.

And I understood you were querying a single index , at least most of the time, right ? Your most recent monthly created index ?

Another (left field) thought : I notice your generated (complex) query has quite a few should clauses. Lucene can be a bit tricky there. Put another way, it’s possible your query isn’t doing what you think it’s doing, ie it’s logically different to what you expect. Since the query is too complex/nested to parse by eye and anyways I’ve no idea what you are trying to search for, I cannot possible know myself.

I return again to the suggestion to reconstruct the query manually, with ANDs and NOTs and so on, all correctly bracketed. Step by step. Test performance at each step. Performance wise, should clauses can often effectively be just score boosters, so unless query optimiser does perfect job there might be a lot of semi-wasted effort in executing the query.

And this thought might also be off-beam, and if so I apologise.