Index selection based on date range

Hi all,

I have below listed index in kibana
Index-2019-09-09
Index-2019-09-10
Index-2019-09-11
Index-2019-09-12
Index-2019-09-13
Index-2019-09-14
Index-2019-09-15

My question is how or is there any api that i can use to list out all the available index from Index-2019-09-10 to Index-2019-09-14 ?

Hi @Bob94,

You could use the search API and the ignore_unavailable parameter to aggregate into the _index field.

Suppose the following indices were created:

PUT index-2019-09-09/_doc/09
{"field": "value"}

PUT index-2019-09-10/_doc/10
{"field": "value"}

PUT index-2019-09-11/_doc/11
{"field": "value"}

PUT index-2019-09-12/_doc/12
{"field": "value"}

PUT index-2019-09-13/_doc/13
{"field": "value"}

PUT index-2019-09-14/_doc/14
{"field": "value"}

PUT index-2019-09-15/_doc/15
{"field": "value"}

Then, the query to find indices from 2019-09-10 to 2019-09-14 would be:

GET index-2019-09-10,index-2019-09-11,index-2019-09-12,index-2019-09-13,index-2019-09-14/_search?ignore_unavailable=true
{
  "size": 0,
  "aggs": {
    "indices_available": {
      "terms": {
        "field": "_index",
        "size": 100
      }
    }
  }
}

And the result:

{
  ...
  "aggregations" : {
    "indices_available" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "index-2019-09-10",
          "doc_count" : 1
        },
        {
          "key" : "index-2019-09-11",
          "doc_count" : 1
        },
        {
          "key" : "index-2019-09-12",
          "doc_count" : 1
        },
        {
          "key" : "index-2019-09-13",
          "doc_count" : 1
        },
        {
          "key" : "index-2019-09-14",
          "doc_count" : 1
        }
      ]
    }
  }
}

I hope it helps!

Cheers,
Luiz Santos

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.