我有文件索引。我希望筛选公开的文档,或者由我的组成员(用户1和3)共享给组的文档。
隐私= "public“或(隐私= "group”和user_id in (1,3))
我可以分开做,但是如何将它们与OR结合起来呢?
"filter" : [
{"terms" : { "privacy" : ["public"]}},
]"filter" : [
{"terms" : { "privacy" : ["group"]}},
{"terms" : { "user_id" : [1,3]}},
]文档:
Company"}
正确的查询将返回文档1、3、4、7、9,但不返回6。
发布于 2020-07-13 14:31:33
诀窍是将两个子查询封装在bool中-应该:
{
"query": {
"bool": {
"should": [
{
"terms": { "privacy": [ "public" ] }
},
{
"bool": {
"filter": [
{
"terms": { "privacy": [ "group" ] }
},
{
"terms": { "user_id": [ 1, 3 ] }
}
]
}
}
]
}
}
}note the difference介于must和filter之间。filter博士放弃评分。
编辑:
{
"terms":{
"privacy":[
"public"
]
}
}大致相同(除上文讨论的得分部分外)
{
"bool":{
"filter":{
"terms":{
"privacy":[
"public"
]
}
}
}
}它完全相当于
{
"bool":{
"filter":[
{
"terms":{
"privacy":[
"public"
]
}
}
]
}
}这只是一个冗长的问题。
编辑2:重写的查询,包括两个过滤器
{
"query": {
"bool": {
"should": [
{
"bool": {
"filter": [
{
"terms": { "privacy": [ "public" ] }
}
]
}
},
{
"bool": {
"filter": [
{
"terms": { "privacy": [ "group" ] }
},
{
"terms": { "user_id": [ 1, 3 ] }
}
]
}
}
]
}
}
}https://stackoverflow.com/questions/62877688
复制相似问题