doubei2231
2016-08-24 06:39
浏览 111
已采纳

不能在Elasticsearch中使用两个或更多过滤器

I'm using Elasticsearch in my project. My Elasticsearch query is like that:

Array(
    [index] => galaxy
    [type] => galaxy
    [size] => 1000
    [from] => 0
    [body] => Array(
        [query] => Array(
            [filtered] => Array(
                [query] => Array(
                    [query_string] => Array(
                        [default_operator] => AND
                        [query] => vestel*
                    )
                )
                [filter] => Array(
                    [bool] => Array(
                        [must] => Array(
                            [term] => Array(
                                [fk_product_category] => 1
                                [fk_product_group] => 1
                            )
                        )
                    )
                )
            )
        )
    )
)

When I remove one of the filters terms for example fk_product_group it works perfectly but when use both filters I get fatal error with code 400 Bad request.

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dsj8000 2016-08-24 06:56
    最佳回答

    Each filter must be in its own term filter

    Array(
        [index] => galaxy
        [type] => galaxy
        [size] => 1000
        [from] => 0
        [body] => Array(
            [query] => Array(
                [filtered] => Array(
                    [query] => Array(
                        [query_string] => Array(
                            [default_operator] => AND
                            [query] => vestel*
                        )
                    )
                    [filter] => Array(
                        [bool] => Array(
                            [must] => Array(
                                Array(
                                   [term] => Array(
                                       [fk_product_category] => 1
                                   )
                                ),
                                Array(
                                   [term] => Array(
                                       [fk_product_group] => 1
                                   )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
    
    评论
    解决 无用
    打赏 举报