Elasticsearch多个术语/过滤器

时间:2019-07-17 12:07:44

标签: php elasticsearch

我正在尝试根据多个术语进行过滤。如果我指定一个术语

,我可以进行过滤
[
  "bool" => [
    "must" => [
      0 => [
        "term" => [
          "interests" => [
            "value" => "art"
          ]
        ]
      ]
    ]
  ]
]

但是当我使用多个术语时,我总是会得到一个空的答复。

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

我误解了我应该如何使用多个术语?

1 个答案:

答案 0 :(得分:1)

php语法对我来说是新的,但是在JSON数组中,您需要将每个term子句包装在其自己的boolmust / filter /等中。因此在JSON中将是这样的:

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