How can the following query's results be sorted by index name?
curl "localhost:9200/_aliases?pretty"
How can the following query's results be sorted by index name?
curl "localhost:9200/_aliases?pretty"
I think that the best way to do this would be via the console. Something like this:
$ curl --silent 'http://path.to.cluster:9200/_cat/indices' | cut -d ' ' -f2 | sort
curl --silent 'http://path.to.cluster:9200/_cat/aliases' | cut -d ' ' -f1 | sort
–
Burnejones -f3
instead of -f2
. –
Smallsword -n(numeric sort)
option and -k(key)
option for sort
instead of using cut
. For example, curl 'localhost:9200/_cat/indices' | sort -nk 3
–
Felicitasfelicitate awk
because the spaces delimiting each column where not constant for me: $ curl --silent 'http://path.to.cluster:9200/_cat/indices' | awk '{ print $3 }' | sort
–
Stratus sort --reverse
–
Stratus You can ask ES to sort the results via the s
(sort) searchParameter using s=i
or s=index
curl "localhost:9200/_cat/indices?pretty&s=i"
curl "localhost:9200/_cat/aliases?pretty&s=index"
To see the column's headers, add "&v" :
curl "localhost:9200/_cat/indices?pretty&v&s=index"`.
You can find some explanations in the cat/indices documentation
/_cat/indices?v&s=docs.count:desc
–
Colly GET _cat/aliases?v&s=index:desc&h=alias,index
Will give you:
alias index
app-logs-alias app-logs-2017-12-31
backend-logs-read backend-logs-2017-12-31
s = sort, v = various extra detail, h = headings to include,
I think that the best way to do this would be via the console. Something like this:
$ curl --silent 'http://path.to.cluster:9200/_cat/indices' | cut -d ' ' -f2 | sort
curl --silent 'http://path.to.cluster:9200/_cat/aliases' | cut -d ' ' -f1 | sort
–
Burnejones -f3
instead of -f2
. –
Smallsword -n(numeric sort)
option and -k(key)
option for sort
instead of using cut
. For example, curl 'localhost:9200/_cat/indices' | sort -nk 3
–
Felicitasfelicitate awk
because the spaces delimiting each column where not constant for me: $ curl --silent 'http://path.to.cluster:9200/_cat/indices' | awk '{ print $3 }' | sort
–
Stratus sort --reverse
–
Stratus This is an old question, but now in 2020 the best way is :
with kibana :
GET _cat/indices/?pretty&s=store.size:desc
with curl :
http://localhost:9200/_cat/indices/?pretty&s=store.size:desc
Desc at the end for sort by desc
Just use this get request it will show all indexes with the column name.
http://localhost:9200/_cat/indices/?pretty&v
Additionally, not only by name you can sort it by any parameter you want with a get parameter of s=column_name
.
for example; to sort by the size you can do like:
http://localhost:9200/_cat/indices/?pretty&s=store.size
similarly for name:
http://localhost:9200/_cat/indices/?pretty&s=index
I don't think it exists by elasticsearch api.
Response from elasticsearch can be
{
"index1": {
"aliases": {}
}
}
Here is a pseudocode to get index from response
If aliasresponse is response from elasticsearch, then
indexlist=[]
for (key in aliasresponse) {
indexlist.add(key)
}
sort(indexlist)
For sorting, you can find libaries or custom methods.
Hope this helps.
© 2022 - 2024 — McMap. All rights reserved.
curl localhost:9200/_cat/aliases | sort
? I realize it's a completely different format, but it might be what you really wanted – Lawrencelawrenciumsort
as @Lawrencelawrencium said. Trycurl localhost:9200/_cat/indices | sort -nk2
– Felicitasfelicitate