elasticsearch - 通过两个条件过滤数组的弹性搜索查询
问题描述
我正在尝试创建一个 Elastic Search 查询来修改收到的数据,但我对 Elastic 了解不多,也不知道如何实现。
我有一系列“任务”,我需要接收按某些条件过滤的那些任务。现在查询过滤: - 必须为特定的“组”分配或创建 - 应该为特定的“用户”分配或创建
组和用户由发出请求的用户确定。
{
"_source": {
"includes": [
"taskId",
"tenantId-createdAt-circuitId",
"assignedToGroup",
"assignedToUser",
"assignedToRole",
"circuitId",
"createdAt",
"createdByRole",
"currentStatus",
"taskType",
"tenantId",
"history",
"payload",
"slaExpiresAt",
"taskDefinitionName",
"taskDefinitionId",
"input"
]
},
"sort": [
{
"createdAt": {
"order": "desc"
}
}
],
"size": 20,
"from": 0,
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"match": {
"tenantId.keyword": "tenant1"
}
},
{
"range": {
"createdAt": {
"gte": "now-1y/d",
"lte": "now+1d/d"
}
}
}
],
"should": [
{
"match": {
"createdByGroup.keyword": "SUPERVISORES"
}
},
{
"match": {
"assignedToGroup": "SUPERVISORES"
}
}
]
}
},
"should": [
{
"match": {
"assignedToUser.keyword": "supervisorsucursal1@btekstudio1.onmicrosoft.com"
}
},
{
"match": {
"createdByUser.keyword": "supervisorsucursal1@btekstudio1.onmicrosoft.com"
}
}
]
}
}
}
我需要开始处理“角色”条件,因此最终查询需要接收: - 为用户组分配或创建的任务(并且还需要接收该组上没有分配任何角色的任务) - 分配的任务到用户的角色 - 为用户创建的分配的任务
这是我的映射https://pastebin.com/yE6PGLDQ 这是一个示例任务https://pastebin.com/p0942qfv
解决方案
推荐阅读
- batch-file - 批次 | 在循环中的两行之间复制文本
- javascript - 'useEffect' 钩子只触发一次?
- python-2.7 - 无法通过在 python 中使用 selenium 为复选框显示的双引号中的值找到元素
- javascript - 尝试根据地图生成列表但无法这样做 - React
- javascript - 如果你得到带有错误的行号,为什么建议使用命名函数进行调试?
- google-cloud-platform - Google Cloud Functions 无法使用 Pub/Sub 死信主题
- python - 为什么 IPython.display.Audio() 在 for 循环中不起作用?
- python - 如何从外部执行嵌套函数
- pyspark - 尝试指定使用 pyspark 加载 CSV 的架构时出错
- javascript - 即使使用无效的密钥,每次都会访问 JSON