{
"id": 9,
"resolutions": [
{
"divisionId": 8
}
]
},
{
"id": 123,
"resolutions": [
{
"employeeId": 1,
"divisionId": 5
},
{
"divisionId": 7
}
]
}索引由document对象组成,每个document都有一个带有对象的数组resolutions。resolution既可以给员工,也可以给部门。员工将同时拥有divisionId和employeeId,但部门只有divisionId。我只需要为部门过滤。
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"bool": {
"should": [
{
"bool": {
"must": [
{
"nested": {
"path": "resolutions",
"query": {
"terms": {
"resolutions.divisionId": [
660
]
}
}
}
}
],
"boost": 1
}
},
{
"bool": {
"must_not": [
{
"nested": {
"path": "resolutions",
"query": {
"exists": {
"field": "resolutions.employeeId"
}
}
}
}
],
"boost": 1
}
}
],
"minimum_should_match": 2,
"boost": 1
}
}
],
"boost": 1
}
}
],
"boost": 1
}
}
}问题是,此查询检查解析数组的所有对象。因此,如果只将一个部门添加到数组中,我就会得到结果,但是如果我还添加了一个雇员,那么我就不会得到它。
如果数组中至少存在一个除法,而不管其他对象是什么,如何修复它以返回结果?
发布于 2022-10-15 05:19:20
你的问题很复杂。
下面将回答我们的查询
如果数组中至少存在一个除法,而不管其他对象是什么?
查询
{
"query": {
"nested": {
"path": "resolutions",
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "resolutions.employeeId"
}
}
],
"filter": [
{
"exists": {
"field": "resolutions.divisionId"
}
}
]
}
}
}
}
}如果要对某些值进行筛选,可以使用术语查询替换筛选器中的存在条件。
如果要查找匹配的嵌套文档,请使用命中。
https://stackoverflow.com/questions/74071408
复制相似问题