猿问

Elasticsearch 多个术语/过滤器

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


[

  "bool" => [

    "must" => [

      0 => [

        "term" => [

          "interests" => [

            "value" => "art"

          ]

        ]

      ]

    ]

  ]

]

但是当我使用多个术语时,我总是得到一个空的回应。


[

  "bool" => [

    "must" => [

      0 => [

        "term" => [

          "interests" => [

            "value" => "art"

          ]

        ]

      ]

      1 => [

        "term" => [

          "community_privacy" => [

            "value" => "private"

          ]

        ]

      ]

    ]

  ]

]

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


繁华开满天机
浏览 110回答 1
1回答

侃侃尔雅

php 语法对我来说是新的,但是在数组中的 JSON 中,您需要将每个 term(s) 子句包装在它自己的bool和must/ filter/ etc 中。所以在 JSON 中它会是这样的:{"query":{    "bool":{        "must":[            {"bool":{                "must":{                    "term":{                        "interests" : "art"                    }                }            }            },            {"bool":{                "must":{                    "term":{                        "community_privacy": "private"                    }                }            }            }        ]    }}}
随时随地看视频慕课网APP
我要回答