简体   繁体   English

Elasticsearch 多个术语/过滤器

[英]Elasticsearch multiple terms/filters

I'm trying to filter based on multiple terms.我正在尝试根据多个术语进行过滤。 I am able to filter if I designate one term如果我指定一个术语,我可以过滤

[
  "bool" => [
    "must" => [
      0 => [
        "term" => [
          "interests" => [
            "value" => "art"
          ]
        ]
      ]
    ]
  ]
]

But when I use multiple terms I'm always getting an empty response.但是当我使用多个术语时,我总是得到一个空的回应。

[
  "bool" => [
    "must" => [
      0 => [
        "term" => [
          "interests" => [
            "value" => "art"
          ]
        ]
      ]
      1 => [
        "term" => [
          "community_privacy" => [
            "value" => "private"
          ]
        ]
      ]
    ]
  ]
]

Am I misunderstanding how I should be using multiple terms?我是否误解了我应该如何使用多个术语?

The php syntax is new for me, but in JSON in an array you need to wrap every term(s) clause in its own bool and must / filter / etc . php 语法对我来说是新的,但是在数组中的 JSON 中,您需要将每个 term(s) 子句包装在它自己的bool并且must / filter / etc 。 So in JSON it would be like this:所以在 JSON 中它会是这样的:

{"query":{
    "bool":{
        "must":[
            {"bool":{
                "must":{
                    "term":{
                        "interests" : "art"
                    }
                }
            }
            },
            {"bool":{
                "must":{
                    "term":{
                        "community_privacy": "private"
                    }
                }
            }
            }
        ]
    }
}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM