【发布时间】:2019-04-18 22:02:43
【问题描述】:
在弹性搜索查询中,我试图搜索具有一系列批准通知的 Document 对象。当dateCompleted 填充了日期时,通知被认为是完整的,当dateCompleted 不存在或存在null 时,通知被认为是待处理的。如果文档不包含一系列批准通知,则它不在搜索范围内。
我知道将 null_value 用于字段 dateCompleted 并将其设置为任意旧日期,但这对我来说似乎很不自然。
我尝试使用带有 must exist doc.approvalNotifications and must not exist doc.approvalNotifications.dateCompleted 的 Bool 查询,但如果文档包含完整和待处理的approvalNotifications,这将不起作用。例如它只返回下面 ID 为 2 的文档。我期待找到 ID 为 1 和 2 的文档。
如何使用 elasticsearch 查找待批准通知?
PUT my_index/_mapping/Document
"properties" : {
"doc" : {
"properties" : {
"approvalNotifications" : {
"properties" : {
"approvalBatchId" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"approvalTransitionState" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"approvedByUser" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"dateCompleted" : {
"type" : "date"
}
}
}
}
}
}
文件:
{
"id": 1,
"status": "Pending Notifications",
"approvalNotifications": [
{
"approvalBatchId": "e6c39194-5475-4168-9729-8ddcf46cf9ab",
"dateCompleted": "2018-11-15T16:09:15.346+0000"
},
{
"approvalBatchId": "05eaeb5d-d802-4a28-b699-5e593a59d445",
}
]
}
{
"id": 2,
"status": "Pending Notifications",
"approvalNotifications": [
{
"approvalBatchId": "e6c39194-5475-4168-9729-8ddcf46cf9ab",
}
]
}
{
"id": 3,
"status": "Complete",
"approvalNotifications": [
{
"approvalBatchId": "e6c39194-5475-4168-9729-8ddcf46cf9ab",
"dateCompleted": "2018-11-15T16:09:15.346+0000"
},
{
"approvalBatchId": "05eaeb5d-d802-4a28-b699-5e593a59d445",
"dateCompleted": "2018-11-16T16:09:15.346+0000"
}
]
}
{
"id": 4
"status": "No Notifications"
}
【问题讨论】:
标签: elasticsearch