弹性搜索:hour_minute_second映射返回空数据 [英] Elastic search: hour_minute_second mapping returns empty data
问题描述
在我为搜索字段创建的映射下面
Below mapping i have created for search field
PUT /sample/_mapping
{
"properties": {
"webDateTime1": {
"type": "date",
"format": "dd-MM-yyyy HH:mm:ss||dd-MM-yyyy||hour_minute_second"
}
}
}
如果我基于"04-04-2019 20:17:18"进行搜索以获取正确的数据如果我根据"04-04-2019"进行搜索以获取正确的数据如果我基于"20:17:18"进行搜索,则不知道总是会得到空的结果.任何帮助将不胜感激.
If i search based on "04-04-2019 20:17:18" getting proper data if i search based on "04-04-2019" getting proper data if i search based on "20:17:18" don't know always getting empty result. Any help would be appreciated.
推荐答案
在摄取一些示例文档时:
When you ingest some sample docs:
POST sample/_doc/1
{"webDateTime1":"04-04-2019 20:17:18"}
POST sample/_doc/2
{"webDateTime1":"04-04-2019"}
POST sample/_doc/3
{"webDateTime1":"20:17:18"}
,然后在日期字段上进行汇总,
and then aggregate on the date field,
GET sample/_search
{
"size": 0,
"aggs": {
"dt_values": {
"terms": {
"field": "webDateTime1"
}
}
}
}
您将看到如何实际上索引值:
...
"buckets" : [
{
"key" : 73038000,
"key_as_string" : "01-01-1970 20:17:18",
"doc_count" : 1
},
{
"key" : 1554336000000,
"key_as_string" : "04-04-2019 00:00:00",
"doc_count" : 1
},
{
"key" : 1554409038000,
"key_as_string" : "04-04-2019 20:17:18",
"doc_count" : 1
}
]
...
这就是您对 20:17:18
的查询使您头疼的原因.
That's the reason your query for 20:17:18
is causing you a headache.
现在,您通常希望像这样使用 range
查询:
Now, you'd typically wanna use the range
query like so:
GET sample/_search
{
"query": {
"range": {
"webDateTime1": {
"gte": "20:17:18",
"lte": "20:17:18",
"format": "HH:mm:ss"
}
}
}
}
注意 format
参数.但是同样,如果您没有在 datetime
字段中提供 date
,那么事实证明它将以Unix纪元作为日期.
Notice the format
parameter. But again, if you don't provide a date
in your datetime
field, it turns out it's going to take the unix epoch as the date.
这篇关于弹性搜索:hour_minute_second映射返回空数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!