Ana içeriğe geç

Slow First Query

Solution Options​

1. Setting Index Search Idle After​

Changes the value that specifies how long a shard cannot receive search or requests until it is considered idle for search.

index.search.idle.after=30sn
Note
  • When this value is increased, the time that needs to pass between two queries for refresh operation increases.
  • This only postpones this problem to occur slightly longer term.
  • It can be considered if it is a frequently queried system.

2. Setting Index Refresh Interval​

Changes the value that specifies how often the refresh operation that makes the latest changes in the index visible for search will be performed.

index.refresh_interval=1sn
Note
  • When this value is increased, refresh is ensured to be done automatically at certain intervals.
  • This leads to outdated data being able to come in query results for a certain period and more consumption of system resources.
  • It is important to set it if querying is not done frequently but the application performing querying needs to be performant.
  • Fine-tuning this refresh time varies according to your needs.

Changing Index Setting​

Info

Index-based settings cannot be made in the elasticsearch.yml file.

Index-based settings can be changed either by using index template or by using index settings API.

API Usage​

Setting on All Indexes​

Below shows setting this setting on all indexes with API usage:

curl -X PUT "<ELASTICSEARCH_IP>:9200/_all/_settings?preserve_existing=true&ignore_unavailable=true" \
--header 'Content-Type:application/json' \
-d '{
"index": {
"refresh_interval": "5s"
}
}'

Setting on Specific Index​

Below shows setting this setting only on the specified index with API usage:

curl -X PUT "<ELASTICSEARCH_IP>:9200/apinizer-log-apiproxy-<INDEX_KEY>/_settings?preserve_existing=true&ignore_unavailable=true" \
--header 'Content-Type:application/json' \
-d '{
"index": {
"refresh_interval": "5s"
}
}'

Index Template Usage​

Below shows setting this setting only for the relevant index using Index Template:

Note

Using Index Template ensures that these settings are automatically applied for newly created indexes.

{
"data_stream": {},
"index_patterns": [
"<INDEX_PATTERN_NAME>"
],
"template": {
"mappings": { ... },
"settings": {
"index": {
"lifecycle": {
"name": "<ILM_POLICY_NAME>"
},
"number_of_replicas": "0",
"number_of_shards": "1",
"refresh_interval": "5s"
}
}
}
}