简体   繁体   English

elasticsearch中如何获取每个索引中数据的最小和最大日期?

[英]How can we get the minimum and maximum dates of data in each indices in elastic search?

How can we get the minimum and maximum dates of data in each indices in elastic search? elasticsearch中如何获取每个索引中数据的最小和最大日期?

I was going through the documentation but not able to understand which API will help get the min and max dates of data in each indices in elastic search.我正在浏览文档,但无法理解哪个 API 将有助于获取弹性搜索中每个索引中数据的最小和最大日期。

Tldr; Tldr;

I believe you could address that using the aggregation feature of Elasticsearch. You could use the Min and Max metric aggregation.我相信您可以使用 Elasticsearch 的aggregation功能来解决这个问题。您可以使用MinMax指标聚合。

Solution解决方案

This would look like that using the api:这看起来像使用 api:

GET <The Index>/_search
{
  "size": 0, 
  "query": {
    "match_all": {}
  },
  "aggs": {
    "min": {
      "min": {
        "field": "<The date>"
      }
    },
    "max":{
      "max": {
        "field": "<The date>"
      }
    }
  }
}

The result should look like so:结果应如下所示:

{
  "took": 0,
  "timed_out": false,
  "_shards": {
...
  },
  "hits": {
    "total": {
      "value": 10000,
      "relation": "gte"
    },
    "max_score": null,
    "hits": []
  },
  "aggregations": {
    "min": {
      "value": 1660521603764,
      "value_as_string": "2022-08-15T00:00:03.764Z"
    },
    "max": {
      "value": 1665431791459,
      "value_as_string": "2022-10-10T19:56:31.459Z"
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Elastic Search 6.5 中更快地获取索引? - How to get the indices faster in Elastic Search 6.5? 如何使用 Jest 在弹性搜索中获取索引的创建时间 - How to get creation time of indices in elastic search using Jest 如何在弹性搜索中仅获取每个项目中的一项? - How to get only 1 of each item in elastic search? 从弹性搜索服务器获取索引 - Get indices from elastic search server 我们如何使用弹性搜索在django rest框架中获得热门搜索列表? - How can we get top trending searched listing in django rest framework using elastic search? 我们可以通过替换Postgres将弹性搜索用作后端数据存储吗? - Can we use Elastic Search as Backend Data Store by replacing Postgres? 我们可以将SOLR中未存储的索引数据迁移到Elastic搜索吗? - Can we migrate non stored Index data in SOLR to Elastic search? 我们可以使用弹性搜索作为缓存来快速检索数据吗? - Can we use elastic search as a cache for fast retrieval of data? 我们如何在没有logstash和beats的情况下通过java将数据摄取到弹性搜索 - How can we ingest data to elastic search through java without logstash and beats 如何定期删除弹性搜索索引? - How to delete elastic search indices periodically?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM