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

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;

{
  "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

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

Can someone provide guidance?

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