【发布时间】:2021-01-07 14:21:10
【问题描述】:
我现在正在做的是获取所有数据并过滤“月中的某天”,例如 2020-01-05、2020-02-05 在熊猫中,
如何在 Elasticsearch 中搜索特定的日期?
我的文档如下所示
{
"took": 80,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1508,
"relation": "eq"
},
"max_score": null,
"hits": [
{
"_index": "test_data",
"_type": "test",
"_id": "SlR42nYBlaUrIoJsVOv6",
"_score": null,
"_source": {
"timestamp": 1609983082524,
"timestampstring": "2021-01-07 09:31:22.524",
"oneNetDevieId": "624232444",
"type": "data"
},
"sort": [
2609983082524
]
},
{
"_index": "test_data",
"_type": "test",
"_id": "6FRL2nYBlaUrIoJsAuba",
"_score": null,
"_source": {
...
我尝试过类似的东西
{
"query": {
"filtered": {
"filter": {
"script": {
"script": "doc.timestampstring.date.dayOfMonth == 5"
}
}
}
}
}
或
{
"query": {
"filtered": {
"filter": {
"script": {
"script": "doc._source.timestampstring.date.dayOfMonth == 5"
}
}
}
}
}
它显示错误 “类型”:“解析异常”, “原因”:“未知查询[过滤]”, “线”:5, "col": 17
或者我需要映射吗?谢谢
编辑更新:
i got the new error:
"reason": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"doc['timestamp'].value.getDayOfMonth() == 5",
" ^---- HERE"
],
"script": "doc['timestamp'].value.getDayOfMonth() == 5",
"lang": "painless",
"position": {
"offset": 22,
"start": 0,
"end": 43
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "dynamic method [java.lang.Long, getDayOfMonth/0] not found"
}
}
}
]
【问题讨论】:
-
这个答案可能会有所帮助:stackoverflow.com/questions/40519806/…(提示:
filtered需要替换为bool)
标签: elasticsearch