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

不能在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
                                   )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 请问有人知道怎么用工艺库里面的sdb文件通过virtuoso导出来library里面每个cell的symbol吗?
  • ¥20 海思 nnie 编译 报错
  • ¥50 决策面并仿真,要求有仿真结果图
  • ¥15 springboot接入微信支付SDK
  • ¥50 大区域的遥感影像匹配 怎么做啊
  • ¥15 求解答:pytorch跑yolov8神经网络受挫
  • ¥20 Js代码报错问题不知道怎么解决
  • ¥15 gojs 点击按钮node的position位置进行改变,再次点击回到原来的位置
  • ¥20 halcon 图像拼接
  • ¥15 webstorm上开发的vue3+vite5+typeScript打包时报错