以下查询的结果如何按索引名称排序?
curl "localhost:9200/_aliases?pretty"
您可以要求 ES 通过s
(sort) searchParameter 使用s=i
or对结果进行排序s=index
curl "localhost:9200/_cat/indices?pretty&s=i"
curl "localhost:9200/_cat/aliases?pretty&s=index"
要查看列的标题,请添加 "&v" :
curl "localhost:9200/_cat/indices?pretty&v&s=index"`.
您可以在cat/indices 文档中找到一些解释
GET _cat/aliases?v&s=index:desc&h=alias,index
会给你:
alias index
app-logs-alias app-logs-2017-12-31
backend-logs-read backend-logs-2017-12-31
s = 排序,v = 各种额外细节,h = 要包含的标题,
我认为最好的方法是通过控制台。像这样的东西:
$ curl --silent 'http://path.to.cluster:9200/_cat/indices' | cut -d ' ' -f2 | sort
这是一个老问题,但现在在 2020 年,最好的方法是:
与 kibana :
GET _cat/indices/?pretty&s=store.size:desc
与卷曲:
http://localhost:9200/_cat/indices/?pretty&s=store.size:desc
Desc 在末尾用于按 desc 排序
只需使用此获取请求,它将显示所有带有列名的索引。
http://localhost:9200/_cat/indices/?pretty&v
此外,不仅可以按名称,您还可以使用 get 参数按所需的任何参数对其进行排序s=column_name
。
例如; 按你可以做的大小排序:
http://localhost:9200/_cat/indices/?pretty&s=store.size
名称类似:
http://localhost:9200/_cat/indices/?pretty&s=index
我不认为它存在于 elasticsearch api。
来自弹性搜索的响应可以是
{
"index1": {
"aliases": {}
}
}
这是从响应中获取索引的伪代码
如果 aliasresponse 是来自 elasticsearch 的响应,则
indexlist=[]
for (key in aliasresponse) {
indexlist.add(key)
}
sort(indexlist)
对于排序,您可以找到库或自定义方法。
希望这可以帮助。