Search code examples
elasticsearchlogstashfilebeat

Daily index not created


On my single test server with 8G of RAM (1955m to JVM) having es v 7.4, I have 12 application indices + few system indices like (.monitoring-es-7-2021.08.02, .monitoring-logstash-7-2021.08.02, .monitoring-kibana-7-2021.08.02) getting created daily. So on an average I can see daily es creates 15 indices.

today I can see only two indices are created.

curl -slient -u elastic:xxxxx 'http://127.0.0.1:9200/_cat/indices?v' -u elastic |  grep '2021.08.03'
Enter host password for user 'elastic':
yellow open   metricbeat-7.4.0-2021.08.03                KMJbbJMHQ22EM5Hfw   1   1     110657            0     73.9mb         73.9mb
green  open   .monitoring-kibana-7-2021.08.03            98iEmlw8GAm2rj-xw   1   0          3            0      1.1mb          1.1mb

and reason for above I think is below,

While looking into es logs, found

[2021-08-03T12:14:15,394][WARN ][o.e.x.m.e.l.LocalExporter] [elasticsearch_1] unexpected error while indexing monitoring document org.elasticsearch.xpack.monitoring.exporter.ExportException: org.elasticsearch.common.ValidationException: Validation Failed: 1: this action would add [1] total shards, but this cluster currently has [1000]/[1000] maximum shards open;

logstash logs for application index and filebeat index

[2021-08-03T05:18:05,246][WARN ][logstash.outputs.elasticsearch][main] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"ping_server-2021.08.03", :_type=>"_doc", :routing=>nil}, #LogStash::Event:0x44b98479], :response=>{"index"=>{"_index"=>"ping_server-2021.08.03", "_type"=>"_doc", "_id"=>nil, "status"=>400, "error"=>{"type"=>"validation_exception", "reason"=>"Validation Failed: 1: this action would add [2] total shards, but this cluster currently has [1000]/[1000] maximum shards open;"}}}}

[2021-08-03T05:17:38,230][WARN ][logstash.outputs.elasticsearch][main] Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"filebeat-7.4.0-2021.08.03", :_type=>"_doc", :routing=>nil}, #LogStash::Event:0x1e2c70a8], :response=>{"index"=>{"_index"=>"filebeat-7.4.0-2021.08.03", "_type"=>"_doc", "_id"=>nil, "status"=>400, "error"=>{"type"=>"validation_exception", "reason"=>"Validation Failed: 1: this action would add [2] total shards, but this cluster currently has [1000]/[1000] maximum shards open;"}}}}

Adding active and unassigned shards totals to 1000

"active_primary_shards" : 512,
  "active_shards" : 512,
  "relocating_shards" : 0,
  "initializing_shards" : 0,
  "unassigned_shards" : 488,
  "delayed_unassigned_shards" : 0,
  "active_shards_percent_as_number" : 51.2

If I check with below command, I see all unassigned shards are replica shards

curl -slient -XGET -u elastic:xxxx http://localhost:9200/_cat/shards | grep 'UNASSIGNED'

.
.
dev_app_server-2021.07.10           0 r UNASSIGNED                            
apm-7.4.0-span-000028               0 r UNASSIGNED                                                      
ping_server-2021.07.02              0 r UNASSIGNED                            
api_app_server-2021.07.17           0 r UNASSIGNED                            
consent_app_server-2021.07.15       0 r UNASSIGNED

Q. So for now, can I safely delete unassigned shards to free up some shards as its single node cluster?

Q. Can I changed the settings from allocating 2 shards (1 primary and 1 replica) to 1 primary shard being its a single server for each index online?

Q. If I have to keep one year of indices, Is below calculation correct?

15 indices daily with one primary shard * 365 days = 5475 total shards (or say 6000 for round off)

Q. Can I set 6000 shards as shard limit for this node so that I will never face this mentioned shard issue?

Thanks,


Solution

  • You have a lot of unassigned shards (probably because you have a single node and all indices have replicas=1), so it's easy to get rid of all of them and get rid of the error at the same time, by running the following command

    PUT _all/_settings
    {
      "index.number_of_replicas": 0
    } 
    

    Regarding the count of the indices, you probably don't have to create one index per day if those indexes stay small (i.e. below 10GB each). So the default 1000 shards count is more than enough without you have to change anything.

    You should simply leverage Index Lifecycle Management in order to keep your index size at bay and not create too many small ones of them.