[{"data":1,"prerenderedAt":239},["ShallowReactive",2],{"post:elasticsearch-performance":3},{"id":4,"title":5,"body":6,"date":227,"description":12,"draft":228,"extension":229,"meta":230,"navigation":231,"path":232,"seo":233,"stem":234,"tags":235,"__hash__":238},"posts\u002Fposts\u002Felasticsearch-performance.md","Improving Elasticsearch Read Performance",{"type":7,"value":8,"toc":219},"minimark",[9,13,16,29,32,35,40,97,106,115,118,160,163,166,212,216],[10,11,12],"p",{},"I've been thinking about Elasticsearch performance lately, and wanted to capture my thoughts here for longterm access.",[10,14,15],{},"There are a number of ways to optimize Elasticsearch for better search performance, and they tend to fall into a few specific categories:",[17,18,19,23,26],"ol",{},[20,21,22],"li",{},"Query design",[20,24,25],{},"Index Configuration",[20,27,28],{},"Hardware and Cluster Design",[10,30,31],{},"Notice that hardware and Elasticsearch (ES) cluster settings tend to go last, because in my experience they have the smallest impact on performance. (Elasticsearch is fast by design and by default!)",[10,33,34],{},"Most of our \"optimization\" will focus on avoiding the more expensive features and simply letting ES be as fast as it already knows how to be.",[36,37,39],"h2",{"id":38},"query-design","Query Design",[41,42,43,53,61,69,76,83,90],"ul",{},[20,44,45,46],{},"Avoid ",[47,48,52],"a",{"href":49,"rel":50},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Fmanage-data\u002Fdata-store\u002Fmapping\u002Fruntime-fields",[51],"nofollow","runtime fields",[20,54,45,55,60],{},[47,56,59],{"href":57,"rel":58},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Fexplore-analyze\u002Ffind-and-organize\u002Fdata-views\u002Fscripted-fields",[51],"scripted fields",". (These are deprecated anyway in favor of runtime fields.)",[20,62,45,63,68],{},[47,64,67],{"href":65,"rel":66},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Freference\u002Felasticsearch\u002Frest-apis\u002Fsort-search-results#script-based-sorting",[51],"script sort",". A Painless sort script was responsible for a 10x search slowdown in a client app I work with. (80ms to 800ms)",[20,70,45,71],{},[47,72,75],{"href":73,"rel":74},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Freference\u002Fquery-languages\u002Fquery-dsl\u002Fquery-dsl-script-score-query",[51],"script score",[20,77,45,78],{},[47,79,82],{"href":80,"rel":81},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Freference\u002Fquery-languages\u002Fquery-dsl\u002Fquery-dsl-function-score-query",[51],"function score",[20,84,45,85],{},[47,86,89],{"href":87,"rel":88},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Freference\u002Fquery-languages\u002Fquery-dsl\u002Fquery-dsl-wildcard-query",[51],"wildcard queries",[20,91,45,92],{},[47,93,96],{"href":94,"rel":95},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Fapi\u002Felasticsearch\u002Foperation\u002Foperation-search#operation-search-size",[51],"large result sizes",[10,98,99,100,105],{},"I think of these as the top 80% of offenders, though there are certainly other ES query features which can have a big impact on search performance. (One example is ",[47,101,104],{"href":102,"rel":103},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Freference\u002Fquery-languages\u002Fquery-dsl\u002Fquery-dsl-percolate-query",[51],"a percolate query",".)",[10,107,108,109,114],{},"For a full reference, check out ",[47,110,113],{"href":111,"rel":112},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Freference\u002Fquery-languages\u002Fquerydsl#query-dsl-allow-expensive-queries",[51],"Limit expensive queries"," in the ES docs.",[36,116,25],{"id":117},"index-configuration",[41,119,120,128,139,150],{},[20,121,122,123],{},"Properly tune your shard count and shard\u002Freplica ratio to account for your document count, index size, and scaling needs. See ",[47,124,127],{"href":125,"rel":126},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Fdeploy-manage\u002Fproduction-guidance\u002Foptimize-performance\u002Fsize-shards",[51],"Size your Elasticsearch shards",[20,129,130,131],{},"Avoid increasing ",[47,132,135],{"href":133,"rel":134},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Freference\u002Felasticsearch\u002Findex-settings\u002Findex-modules#index-max-result-window",[51],[136,137,138],"code",{},"index.max_result_window",[20,140,141,142,149],{},"Adjust ",[47,143,146],{"href":144,"rel":145},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Freference\u002Felasticsearch\u002Findex-settings\u002Findex-modules#dynamic-index-settings",[51],[136,147,148],{},"index.refresh_interval"," to the maximum duration you can allow stale results.",[20,151,141,152,159],{},[47,153,156],{"href":154,"rel":155},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Freference\u002Felasticsearch\u002Fconfiguration-reference\u002Ffield-data-cache-settings",[51],[136,157,158],{},"indices.fielddata.cache.size"," to prevent unbounded field cache growth.",[10,161,162],{},"Again, this is an intentionally short list of what I consider the \"low hanging fruit\" of optimizing ES read performance.",[36,164,28],{"id":165},"hardware-and-cluster-design",[41,167,168,177,191,199,202],{},[20,169,170,171,176],{},"Make sure your ",[47,172,175],{"href":173,"rel":174},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Fapi\u002Felasticsearch\u002Foperation\u002Foperation-health-report",[51],"cluster health is green",", meaning all shards (including replicas) are allocated.",[20,178,179,180,184,185,190],{},"Watch your node heap size - ES recommends ",[181,182,183],"em",{},"at most"," 50% of available RAM too avoid starving the OS. (Watch for OOM exceptions.) See ",[47,186,189],{"href":187,"rel":188},"https:\u002F\u002Fwww.elastic.co\u002Fsearch-labs\u002Fblog\u002Felasticsearch-heap-size-jvm-garbage-collection",[51],"Elasticsearch heap size usage and JVM garbage collection",".",[20,192,193,194,190],{},"Have ",[47,195,198],{"href":196,"rel":197},"https:\u002F\u002Fwww.elastic.co\u002Fdocs\u002Fdeploy-manage\u002Fdistributed-architecture\u002Fclusters-nodes-shards\u002Fnode-roles",[51],"dedicated ingest nodes, and dedicated search nodes",[20,200,201],{},"Make sure your ingest payloads are tuned to match the node RAM and CPU resources.",[20,203,204,205,211],{},"Ensure ",[47,206,208],{"href":111,"rel":207},[51],[136,209,210],{},"search.allow_expensive_queries"," is enabled in the cluster settings.",[36,213,215],{"id":214},"conclusion","Conclusion",[10,217,218],{},"As I said earlier, Elasticsearch is fast by default. There are a number of features, however, which are computationally expensive and should be avoided for performance reasons. Besides that, as Elasticsearch clusters grow more time should be dedicated to tuning the shard count\u002Freplica count, heap, and other cluster management settings that can have an outsized effect on performance",{"title":220,"searchDepth":221,"depth":221,"links":222},"",2,[223,224,225,226],{"id":38,"depth":221,"text":39},{"id":117,"depth":221,"text":25},{"id":165,"depth":221,"text":28},{"id":214,"depth":221,"text":215},"2026-11-25T06:22:06-04:00",false,"md",{},true,"\u002Fposts\u002Felasticsearch-performance",{"title":5,"description":12},"posts\u002Felasticsearch-performance",[236,237],"elasticsearch","performance","IkwBbscrGTktCmN4f1Ex12KJJPoix4Na8jJc3v1dveQ",1795608397636]