Authoritative Guide to Elasticsearch Search Tuning – Rounded Date Queries, Global Ordinals Warmup, and File System Cache Preloading
This third‑part guide for Elasticsearch 5+ shows how rounding date ranges, eagerly loading global ordinals for keyword fields, and pre‑loading index files into the OS cache—each illustrated with curl commands—can improve search latency while requiring careful trade‑offs between cache friendliness, query complexity, and resource usage.
This article is the third part of QBox's "Authoritative Guide to Elasticsearch Search Tuning" series, targeting Elasticsearch 5.0+ users. It presents practical techniques for improving query performance through rounded date queries, global ordinals warmup, and file‑system cache preloading, each accompanied by concrete curl examples.
1. Rounded ("凑整") Date Queries
Range queries on now cannot be cached because the time window constantly changes. By rounding the date to a coarser granularity (e.g., minute), the query becomes cache‑friendly while remaining acceptable for most user experiences.
Original query example:
curl -XPUT 'ES_HOST:ES_PORT/index/type/1?pretty' -H 'Content-Type: application/json' -d '{
"my_date": "2016-05-11T16:30:55.328Z"
}'
curl -XGET 'ES_HOST:ES_PORT/index/_search?pretty' -H 'Content-Type: application/json' -d '{
"query": {
"constant_score": {
"filter": {
"range": {
"my_date": {
"gte": "now-1h",
"lte": "now"
}
}
}
}
}
}'Rounded to minute:
curl -XGET 'ES_HOST:ES_PORT/index/_search?pretty' -H 'Content-Type: application/json' -d '{
"query": {
"constant_score": {
"filter": {
"range": {
"my_date": {
"gte": "now-1h/m",
"lte": "now/m"
}
}
}
}
}
}'By splitting the range into a cacheable part and a non‑cacheable part, the query can benefit from the cache, though the added Boolean logic may offset gains in some cases.
2. Global Ordinals Warmup
Elasticsearch lazily loads global ordinals for keyword fields used in term aggregations. Pre‑loading them can reduce latency spikes at query time, especially for high‑cardinality fields.
Mapping to enable eager global ordinals:
curl -XPUT 'ES_HOST:ES_PORT/index?pretty' -H 'Content-Type: application/json' -d '{
"mappings": {
"type": {
"properties": {
"foo": {
"type": "keyword",
"eager_global_ordinals": true
}
}
}
}
}'While eager loading improves query latency, it may increase refresh time for very high‑cardinality fields. Adjusting refresh_interval can mitigate the impact.
3. File System Cache Preloading
Elasticsearch relies on the OS file‑system cache for I/O. The setting index.store.preload can instruct the OS to load specific index files (e.g., nvd, dvd) into memory at startup, speeding up subsequent searches.
Static configuration (elasticsearch.yml):
index.store.preload: ["nvd", "dvd"]Or set during index creation:
curl -XPUT 'ES_HOST:ES_PORT/my_index' -d '{
"settings": {
"index.store.preload": ["nvd", "dvd"]
}
}'Preloading helps hot indexes but may increase index opening time and can be counter‑productive if the cache cannot hold all preloaded data.
Overall, the guide emphasizes balancing cache friendliness, query complexity, and resource consumption to achieve consistent search performance.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
vivo Internet Technology
Sharing practical vivo Internet technology insights and salon events, plus the latest industry news and hot conferences.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
