# Picking latest index in kibana dashboard

**URL:** https://discuss.elastic.co/t/picking-latest-index-in-kibana-dashboard/192945
**Category:** Kibana
**Created:** [July 30, 2019, 4:17pm UTC](https://discuss.elastic.co/t/picking-latest-index-in-kibana-dashboard/192945 "2019-07-30T16:17:37Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![pmehra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmehra/32/46188_2.png) [@pmehra](https://discuss.elastic.co/u/pmehra)
#### Post date: [July 30, 2019, 4:17pm UTC](https://discuss.elastic.co/t/picking-latest-index-in-kibana-dashboard/192945/1 "2019-07-30T16:17:37Z")

</div>

We are using a rollover indexing strategy where each software run would result in two new indexes everyday, for example

> somestaticname-a-.2019.07.16\_01.00.04, somestaticname-b-.2019.07.16\_01.00.04  
> somestaticname-a-.2019.07.17\_11.00.05, somestaticname-b-.2019.07.17\_11.00.05  
> somestaticname-a-.2019.07.18\_01.02.09, somestaticname-b-.2019.07.18\_01.02.09

On kibana dashboard, we have a filter to manually select a date, something like below

```
    query
        "match": {
          "_index": {
            "query": "somestaticname-*-.2019.07.18*>",
            "type": "phrase"
          }
        }
      }
}

```

The above approach successfully choose the index and render dashboard accordingly but can it automatically take the latest date "now" and render the latest index so that user have less cognitive load of finding whether dashboard is current or of some earlier date. Can you please let us know if it's possible? or suggest any potential solutions.

---

<div class="post-metadata">

### Author: ![jen-huang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jen-huang/32/74327_2.png) [@jen-huang](https://discuss.elastic.co/u/jen-huang)
#### Post date: [July 30, 2019, 6:16pm UTC](https://discuss.elastic.co/t/picking-latest-index-in-kibana-dashboard/192945/2 "2019-07-30T18:16:34Z")

</div>

Hi, one idea I have is to set up an [Index Alias](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html). For example this will create the alias `latest_somestaticname` that points to 2019.07.18 indices:

```auto
POST /_aliases
{
    "actions" : [
        { "add" : { "index" : "somestaticname-*-.2019.07.18*", "alias" : "latest_somestaticname" } }
    ]
}

```

Then you can set up an index pattern that uses the alias `latest_somestaticname` instead of the time series index names and use that index pattern for the dashboard.

However this will require you to update the alias after the new indices are created each day. Would this be possible to integrate into your rollover workflow or a separate cron script?

Another similar idea is to use a [Filtered Alias](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#filtered) on the pattern `somestaticname-*-*` and filtering by some date field.

---

<div class="post-metadata">

### Author: ![pmehra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmehra/32/46188_2.png) [@pmehra](https://discuss.elastic.co/u/pmehra)
#### Post date: [July 30, 2019, 7:08pm UTC](https://discuss.elastic.co/t/picking-latest-index-in-kibana-dashboard/192945/3 "2019-07-30T19:08:42Z")

</div>

Thanks for your response!

Yes, this looks like a promising solution. So I am reading alias documentation here [https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html](https://www.elastic.co/guide/en/elasticsearch/reference/2.0/indices-aliases.html)

So essentially, we have to make two calls

1. One to find last alias association with index
2. Remove alias from the old index and associate with the new one.

Is there an option where disassociation with last index happens automatically when we associate alias with the latest index? I don't want to write logic to search and remove last associated index.

---

<div class="post-metadata">

### Author: ![jen-huang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jen-huang/32/74327_2.png) [@jen-huang](https://discuss.elastic.co/u/jen-huang)
#### Post date: [July 30, 2019, 8:17pm UTC](https://discuss.elastic.co/t/picking-latest-index-in-kibana-dashboard/192945/4 "2019-07-30T20:17:15Z")

</div>

It can happen in one call where the actions are done in sequence. For example first the remove action removes the alias from all indices with your pattern, and then the add action adds the alias to the most recent index:

```auto
POST _aliases
{
  "actions": [
    {
      "remove": {
        "index": "somestaticname-*-*",
        "alias": "latest_somestaticname"
      }
    },
    {
      "add": {
        "index": "somestaticname-*-.2019.07.18*",
        "alias": "latest_somestaticname"
      }
    }
  ]
}

```

---

<div class="post-metadata">

### Author: ![pmehra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pmehra/32/46188_2.png) [@pmehra](https://discuss.elastic.co/u/pmehra)
#### Post date: [July 31, 2019, 4:50pm UTC](https://discuss.elastic.co/t/picking-latest-index-in-kibana-dashboard/192945/5 "2019-07-31T16:50:33Z")

</div>

Thank you, we can implement this easily.

---

<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: [August 28, 2019, 4:50pm UTC](https://discuss.elastic.co/t/picking-latest-index-in-kibana-dashboard/192945/6 "2019-08-28T16:50:34Z")

</div>

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