【问题标题】:Query the latest created index in Elasticsearch在 Elasticsearch 中查询最新创建的索引
【发布时间】:2020-03-10 02:13:31
【问题描述】:

我需要查询在 Elasticsearch 上创建的最新索引。

我已经形成了下面的 curl 命令

curl -X GET "localhost/_cat/indices?h=i,creation.date.string"

它返回的响应如下:

accounting       2020-03-03T02:46:29.285Z
kibana_1         2020-03-02T00:58:14.386Z 

有什么方法可以以 JSON 格式返回?我一直在尝试,但无法获得 JSON 响应。

【问题讨论】:

  • 在 curl 命令中尝试 -H 'Content-Type: application/json'
  • 这个返回 json 格式,日期为 Unix 时间戳 curl -X GET "localhost/_all/_settings/index.creation_date"

标签: elasticsearch elasticsearch-query amazon-elasticsearch


【解决方案1】:

确实可以从_cat API in JSON 返回响应。也可以通过creation.date.stringsort the results

试试这个,结果数组中的第一个元素将是最后一个创建索引。

curl -H "Content-type: application/json" -X GET "localhost/_cat/indices?h=i,creation.date.string&format=json&s=creation.date.string:desc"

【讨论】:

  • 如果索引的前缀已知,则稍作修改。 curl -H "Content-type: application/json" -X GET "localhost:9200/_cat/indices/index-prefix-*?h=i,creation.date.string&format=json&s=creation.date.string:desc&pretty"
【解决方案2】:

您可以在查询中传递格式 /_cat/indices?format=json&h=i,creation.date.string

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-16
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 2018-05-14
    • 2014-05-30
    • 1970-01-01
    相关资源
    最近更新 更多