简体   繁体   English

如何查询Elasticsearch以获取两个时间戳之间的数据

[英]How to query elasticsearch to get data between two timestamps

Recently I have been using a timestamp based query to get data form my ELK stack and avoid repeats. 最近,我一直在使用基于时间戳的查询来获取我的ELK堆栈中的数据并避免重复。 Now I would like to implement getting information between two specific timestamps. 现在,我想实现在两个特定时间戳之间获取信息。

Here is my current query: 这是我当前的查询:

{
  "query": {
    "range": {
      "runtime_timestamp": {
       "gt": "2017-03-18T22:00:55.964Z"
    }  
   }
  },
  "_source": {
  "includes": [
  "field1",
  "field2"
]
},
"sort": [
{
  "@timestamp": {
    "order": "desc"
  }
}
]
}

I have looked at the docs and I can't seem to find a way to do it. 我看了看文档,但似乎找不到解决方法。 Any ideas? 有任何想法吗?

You can add a "lt" or "lte" to your existing range query as described here: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-query.html 您可以按以下说明在现有范围查询中添加“ lt”或“ lte”: https : //www.elastic.co/guide/zh-CN/elasticsearch/reference/current/query-dsl-range-query.html

{
  "query": {
    "range": {
      "runtime_timestamp": {
        "gt": "2017-03-18T22:00:00.000Z",
        "lt": "2017-03-18T22:10:00.000Z"
      }
    }
  },
  "_source": {
    "includes": [
      "field1",
      "field2"
    ]
  },
  "sort": [
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ]
}

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM