# Index selection based on date range

**URL:** <https://discuss.elastic.co/t/index-selection-based-on-date-range/199292>\
**Category:** Elasticsearch\
**Created:** [September 12, 2019, 4:45pm UTC](https://discuss.elastic.co/t/index-selection-based-on-date-range/199292 "2019-09-12T16:45:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bob94](https://avatars.discourse-cdn.com/v4/letter/b/c89c15/32.png) [@Bob94](https://discuss.elastic.co/u/Bob94)\
**Post date:** [September 12, 2019, 4:45pm UTC](https://discuss.elastic.co/t/index-selection-based-on-date-range/199292/1 "2019-09-12T16:45:51Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![luiz.santos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/luiz.santos/32/24664_2.png) [@luiz.santos](https://discuss.elastic.co/u/luiz.santos)\
**Post date:** [September 23, 2019, 11:52am UTC](https://discuss.elastic.co/t/index-selection-based-on-date-range/199292/2 "2019-09-23T11:52:21Z")

</div>

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:

```auto
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:

```auto
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:

```auto
{
  ...
  "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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [October 21, 2019, 12:03pm UTC](https://discuss.elastic.co/t/index-selection-based-on-date-range/199292/3 "2019-10-21T12:03:14Z")

</div>

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