Is it possible to get a list of indexes that match a certain pattern e.g
this is how to get a list of indexes:
curl -XGET 'localhost:9200/_stats/'
but I couldn't find a way of filter them so that this list would only include only indexes witch match "my_index_nr_1*" where "*" would be a wild card
After using ES for quite a while here is what I use now, hope it will help someone else:
curl -XGET '/_cat/indices/my_index_nr_1*'
You can also add ?v
at the end which will give you headers of each column in result.
You can query localhost:9200/_status and that will give you a list of indices and information about each. The response will look something like this: { "ok" : true, "_shards" : { ... }, "indices" : { "my_index" : { ... }, "another_index" : { ... } } }
Indexes are stored on disk as configured in elasticsearch. yml with the configuration option path. data ; localhost on port 9200 is the default connection port for the HTTP REST interface, the path of the url generally defines an action to be taken (like searching for documents);
You'll need to use Python's PIP3 package manager to install the Elasticsearch low-level client for Python. Use the pip3 -V command to check if PIP is installed, and you can input pip3 list to see which packages are already installed.
There is a neat trick using the _aliases command that when combined with a wildcard (my_index_nr_1*
below) will only show you matching index names and associated indexes:
curl -XGET 'http://localhost:9200/my_index_nr_1*/_aliases?pretty'
The result I get is:
{ "my_index_nr_1_test" : { "aliases" : { } } }
Very helpful when you have a lot of indexes on a cluster but don't want to see all the other stats information.
For humans, the best answer is the modified summary:
curl -XGET localhost:9200/_cat/indices/my_index_nr_1*?v
For machines, the best answer is likely a variation of (?pretty
is there for you to see its output):
curl -XGET localhost:9200/my_index_nr_1*/_settings?pretty
This will get the list of all indices that match, with their settings. The _aliases
answer above is just a variation of this request. You can even trim the request down to:
curl -XGET localhost:9200/my_index_nr_1*?pretty
However, this will respond with both the settings, aliases, and mappings of each index.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With