弹性搜索查询,使用 curl 获取特定日期之间的记录


curl -X GET 'http://xxx.xxx.x.xx:9200/upslinklog/upslinklog/_search?pretty' -d '{
    "query": {
        "filtered": {
            "query": {
                "match_all": {}
            },
            "filter": {
                "range": {
                    "logTimestamp": {
                        "gte": "2017/05/17", 
            "lte":"2017/05/18"
                "format": "yyyy/mm/dd"
                    }
                }
            }
    }
}
'

我想在 17/5/2017 之后进行记录.上面的查询代码给出了所有记录而不是一些记录。如何对过滤后的数据进行范围查询

首先,您必须在索引配置中将logTimestamp指定为日期。

来自 Elasticsearch 文档 "Date 数据类型">

索引配置示例:

PUT my_index
{
  "mappings": {
    "my_type": {
      "properties": {
        "date": {
          "type": "date" 
        }
      }
    }
  }
}

然后,您可以使用简单的范围查询,如下所示:

GET _search
{
    "query": {
        "range" : {
            "born" : {
                "gte": "01/01/2012",
                "lte": "01/01/2013",
                "format": "dd/MM/yyyy"
            }
        }
    }
}

最新更新