我正在尝试按必须为空或包含项1
的数组进行过滤。
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"terms": {
"memberOrganizationFamilyIds": [
1
]
}
}
],
"must_not": [
{
"exists": {
"field": "memberOrganizationFamilyIds"
}
}
]
}
}
}
}
}
根据文档,这应该是应该的,但它不起作用。
如果我们应用第一个过滤器,它将起作用。
{
"query": {
"bool": {
"filter": {
"bool": {
"must": [
{
"terms": {
"memberOrganizationFamilyIds": [
1
]
}
}
]
}
}
}
}
}
如果我们应用第二个过滤器,它也将起作用。
{
"query": {
"bool": {
"filter": {
"bool": {
"must_not": [
{
"exists": {
"field": "memberOrganizationFamilyIds"
}
}
]
}
}
}
}
}
但不能在一起。
答案 0 :(得分:1)
我正在尝试按必须为空或包含项目1的数组进行过滤
尝试此操作,您应该添加should
(意思是or
{
"query": {
"bool": {
"filter": {
"bool": {
"should": [
{
"terms": {
"memberOrganizationFamilyIds": [
1
]
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "memberOrganizationFamilyIds"
}
}
]
}
}
]
}
}
}
}
}