Ayur Sharma
Ayur Sharma

Reputation: 31

Filter indices by date range in OpenSearch

I am using this endpoint to fetch indices:

{{OPENSEARCH_ENDPOINT}}/_cat/indices?h=h,s,i,id,p,r,dc,dd,ss,creation.date.string

Result:

green open fluent-bit-2023.04               nA-VlnELTL2igAroKB0CuQ 5 1   487819     0 247.3mb 2023-04-01T00:00:00.324Z
green open fluent-bit-2023.02               YL9re7_mR06td3gH3p3vlg 5 1   178616     0 106.3mb 2023-02-24T07:31:28.508Z
green open fluent-bit-2023.03               ebnxgf2JQQCh4PKpyKIAqA 5 1  2512232     0   1.4gb 2023-03-01T00:00:00.199Z

How can I filter it on the basis of date. I want to fetch all indices created between 2 date range. I tried this using curl but it didn't work:

curl -X GET "http://BASE_URL/_cat/indices/?v&s=index&pretty" --header "Content-Type:application/json" -d'
> {
>   "query": {
>     "bool": {
>       "must": [
>         {
>           "range": {
>             "creation.date.string": {
>               "gte": "2023-03-15",
>               "lte": "2023-03-16"
>             }
>           }
>         }
>       ]
>     }
>   }
> }'

Upvotes: 0

Views: 614

Answers (1)

A.Stern
A.Stern

Reputation: 103

Currently, there are no options to do this on OpenSearch. I recommend getting the response and filtering through it using some other method.

Alternatively, for less fine-grained searches you can use aliases. For example, if you added the following aliases to the indices:

fluent-bit-2023.04 -> fluent-bit-2023-04-01
fluent-bit-2023.02 -> fluent-bit-2023-02-24
fluent-bit-2023.03 -> fluent-bit-2023-03-01

and then search for indices in March of 2023 using wildcards, like so:

{{OPENSEARCH_ENDPOINT}}/_cat/indices/fluent-bit-2023-3-*?h=h,s,i,id,p,r,dc,dd,ss,creation.date.string

Upvotes: 0

Related Questions