在Elasticsearch中按日期过滤
我正在尝试搜索日期范围内的日期范围内的所有项目,但失败(不返回任何结果)
查询:
{ "query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"range": {
"last_updated": {
"from": "2013-01-01 00:00:00"
}
}
}
}
}
}
映射:
{ "my_doctype": {
"_timestamp": {
"enabled": "true"
},
"properties": {
"cards": {
"type": "integer"
},
"last_updated": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
}
结果是:
{ took: 1
timed_out: false
_shards: {
total: 1
successful: 1
failed: 0
}
hits: {
total: 0
max_score: null
hits: [ ]
}
}
通过一个带数字值的整数字段(“ cards”)的范围过滤的同一查询工作正常。将日期更改为非常早的开始(1900-01-01
00:00:00)也不会显示任何结果。
我究竟做错了什么?
顺便说一句,我知道我在映射中启用了_timestamp,但这不是我要过滤的字段。
回答:
似乎对我来说很好:
curl -XPUT localhost:9200/test -d '{ "settings": {
"index.number_of_shards": 1,
"index.number_of_replicas": 0
},
"mappings": {
"doc": {
"_timestamp": {
"enabled": "true"
},
"properties": {
"cards": {
"type": "integer"
},
"last_updated": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
}
}
'
curl -XPOST localhost:9200/test/doc/1 -d '{
"last_updated": "2012-01-01 12:13:14"
}
'
curl -XPOST localhost:9200/test/doc/2 -d '{
"last_updated": "2013-02-02 01:02:03"
}
'
curl -X POST 'http://localhost:9200/test/_refresh'
echo
curl -X GET 'http://localhost:9200/test/doc/_search?pretty' -d '{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"range": {
"last_updated": {
"gte": "2013-01-01 00:00:00"
}
}
}
}
}
}
'
以上是 在Elasticsearch中按日期过滤 的全部内容, 来源链接: utcz.com/qa/423807.html