有许多以下类型的对象: 映射:
{ "_index": "crm", "_type": "order", "_id": "1", "_score": 1.0, "_source": { "executionPercent": 50, "phase": [ { "phaseId": "1", "phaseName": "phaseOne", "startDateTime": "2019-11-12T18:09:51.894Z", "endDateTime": "2019-11-12T21:15:43.797Z" }, { "phaseId": "2", "phaseName": "phaseTwo", "startDateTime": "2019-11-12T21:15:43.797Z" } ], } }, { "_index": "crm", "_type": "order", "_id": "2", "_score": 1.0, "_source": { "executionPercent": 10, "phase": [ { "phaseId": "1", "phaseName": "phaseOne", "startDateTime": "2019-11-13T06:37:45.850Z" } ], } }
我需要搜索"相位"数组(第一个元素(中的 startDateTime 介于 dateFrom 和 dateTo 之间的对象 查询:
{
"query": {
"filter": {
"script": {
"params": {
"dateFrom": 2019-11-11
"dateTo": 2019-11-12
},
"script": "doc['startDateTime'][0].value > dateFrom && doc['startDateTime'][0].value < dateTo"
}
}
}
}
也许使用"lang":"无痛"? 对不起我的英语和代码
范围查询可用于基于日期字段搜索文档。下面是一个示例代码,用于查找在给定的开始日期和结束日期之间具有 startDateTime 的文档。
GET crm/_search
{
"query": {
"range": {
"phase.startDateTime": {
"from": "2019-11-11",
"to": "2019-11-12"
}
}
}
}