【问题标题】:How correctly to filter entries by date range in Elasticsearch?如何在 Elasticsearch 中按日期范围正确过滤条目?
【发布时间】:2019-03-29 14:06:56
【问题描述】:

我正在尝试过滤Elasticsearch 中的期间的条目。我使用 Elasticsearch version 6.4.1

我使用这样的网址

http://localhost:9200/index_name/_search?q=stamper:[2018-10-01T00:00:00.000Z+TO+2018-10-07T23:59:59.999Z]&q=city=London

结果我看到所有关于伦敦市的条目,但日期范围过滤器不起作用。如何解决?

我检查了 Kibana 中stamper 字段的格式。它告诉我这个:

Type: date
Format: Date

Result 示例:

"hits": [
    {
        "_index": "youtube",
        "_type": "doc",
        "_id": "K6OKZ2YBmp2VWXSDhFPc",
        "_score": 0.9570947,
        "_source": {
            "avg": 6258.5,
            "price": "2259",
            "region": "England",
            "@version": "1",
            "description_id": "7406",
            "stamper": "2018-09-28T08:00:00.000Z",,
            "area": "London",
            "datefor": "2018-09-28",
            "@timestamp": "2018-10-12T09:10:23.103Z",
            "city": "London",
        }
    },
    [***]
]

我注意到,如果我们从 URL 中删除 &q=city=London,它会返回所有城市期间的所有条目。看来我的网址不正确。如何制作正确的多参数网址?

【问题讨论】:

    标签: json elasticsearch elastic-stack


    【解决方案1】:

    正确的搜索网址是:

    http://localhost:9200/index_name/_search?q=stamper:[2018-10-01T00:00:00.000Z+TO+2018-10-07T23:59:59.999Z] AND city:London
    

    编码后会是这样的:

    http://localhost:9200/index_name/_search?q=stamper:[2018-10-01T00:00:00.000Z+TO+2018-10-07T23:59:59.999Z]%20AND%20city:London
    

    【讨论】:

      【解决方案2】:

      终于找到问题的原因了。网址不正确。

      如果您想在 URL 中使用 multiple parameters,请使用:

      http://localhost:9200/index_name/_search?q=stamper:[2018-10-01T00:00:00.000Z+TO+2018-10-07T23:59:59.999Z]%20AND%20city:London
      

      【讨论】:

      • 还是不正确,结尾应该是city:London(用:不是=
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-23
      • 1970-01-01
      • 1970-01-01
      • 2020-03-05
      • 1970-01-01
      相关资源
      最近更新 更多