在elasticsearch中,如何查询所有日期字段是太平洋时区2020年1月1日任何时间的文档。

问题描述 投票:0回答:1

在elasticsearch中,如何查询所有日期字段为2020年1月1日太平洋时区的文档。我只是不知道如何指定太平洋时区。

elasticsearch elasticsearch-5
1个回答
0
投票
{
  "version": true,
  "size": 500,
  "sort": [
    {
      "inserted_date": {
        "order": "desc",
        "unmapped_type": "boolean"
      }
    }
  ],
  "aggs": {
    "2": {
      "date_histogram": {
        "field": "inserted_date",
        "fixed_interval": "30m",
        "time_zone": "America/Los_Angeles",
        "min_doc_count": 1
      }
    }
  },
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "match_all": {}
        },
        {
          "range": {
            "inserted_date": {
              "gte": "2019-12-31T18:30:00.000Z",
              "lte": "2020-01-01T18:29:59.000Z",
              "format": "strict_date_optional_time"
            }
          }
        }
      ],
      "should": [],
      "must_not": []
    }
  }
}

这可能对你有帮助。


0
投票

太平洋时区可以用IANA时区或UTC偏移值来表示(如果使用这个,请注意夏令时)。

UTC偏移值

GET /_search
{
  "query": {
    "range": {
      "timestamp": {
        "time_zone": "-08:00",        
        "gte": "2020-01-01T00:00:00", 
      }
    }
  }
}

IANA时区

GET /_search
    {
      "query": {
        "range": {
          "timestamp": {
            "time_zone": "America/Los_Angeles",        
            "gte": "2020-01-01T00:00:00", 
          }
        }
      }
    }
© www.soinside.com 2019 - 2024. All rights reserved.