gpt4 book ai didi

elasticsearch - elasticsearch无痛阵列第一要素

转载 作者:行者123 更新时间:2023-12-03 02:30:43 25 4
gpt4 key购买 nike

有许多以下类型的对象:
映射:

  {
"_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"
}
],
}
}


我需要搜索“phase”数组(第一个元素)中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"
}
}
}
}

关于elasticsearch - elasticsearch无痛阵列第一要素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60076897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com