# Getting Alias definition for most recent index when index name is unknown

**URL:** <https://discuss.elastic.co/t/getting-alias-definition-for-most-recent-index-when-index-name-is-unknown/225968>\
**Category:** Elasticsearch\
**Created:** [April 1, 2020, 3:37am UTC](https://discuss.elastic.co/t/getting-alias-definition-for-most-recent-index-when-index-name-is-unknown/225968 "2020-04-01T03:37:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![lmit](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lmit](https://discuss.elastic.co/u/lmit)\
**Post date:** [April 1, 2020, 3:37am UTC](https://discuss.elastic.co/t/getting-alias-definition-for-most-recent-index-when-index-name-is-unknown/225968/1 "2020-04-01T03:37:25Z")

</div>

I am trying to write a single query to retrieve the most recent Alias definition , where I do NOT know the name of the most recent index ( because index names include a date stamp, e.g. **canpi-v1-2020.03.02** )

The API documentation gives me two options

> GET /\_alias/canpi-v1-managers

or

> GET /canpi-v1-2020.03.\*/\_alias/canpi-v1-managers

The first option is SLOW and not scaleable as more data is returned as the dataset grows  
The second option has bugs where i'll get 404 if the month i pick does not yet include indexes during rollovers between months at times when my DSL query is called before an index is actually created. I would then need to write more code to respond to the 404 and choose the prior month.

I'm hoping to simplify my code by using a single DSL query to get the **alias definition** ONLY for the most recent index no matter what month/day it falls on.

I can't seem to find in the documentation a combination of query that returns **alias definitions** ;

```auto
{
  "canpi-v1-2020.03.31" : {
    "aliases" : {
      "canpi-v1-managers" : {
        "filter" : {
          "terms" : {
            "vehicle.customer_type_id" : [
              "customer_test_group",
              "admin_group",
              "managers_group"
            ]
          }
        }
      }
    }
  }
}

```

With the power of \_search by timestamp

```auto
GET testindex/_search
{
  "query": {
    "match": {
      "project_id": "1"
    }
  },
  "sort": [
    {
      "timestamp": {
        "order": "desc"
      }
    }
  ],
  "size": 1
}

```

Can someone provide guidance?

---

<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:** [April 29, 2020, 3:44am UTC](https://discuss.elastic.co/t/getting-alias-definition-for-most-recent-index-when-index-name-is-unknown/225968/2 "2020-04-29T03:44:28Z")

</div>

Closed on April 29, 2020, 3:44am UTC

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