douweng1935 2018-10-10 13:17
浏览 65
已采纳

搜索两个过滤器与Elasticsearch匹配的位置

I am doing a search with elasticSearch but I would like to filter it and the search must match both filters.

this is the code:

"query" => [
                            "bool" => [
                                "must" => [
                                    'multi_match'=> [
                                        'query'=> $this->input->get('search'),
                                        'fields'=> ["title^2", "description"]
                                    ]
                                ],
                                "filter" => [
                                    "terms" => [ 
                                        "Categories" => ['Featured Works']
                                    ],
                                    "terms" => [
                                        "Tags" => ['Merida']
                                    ]
                                ]
                            ]
                        ]

Bring the search results but take the filter as an OR and I would like an AND

  • 写回答

1条回答 默认 最新

  • dongxiong2000 2018-10-10 13:21
    关注

    The problem lies in how you define your terms filter in a PHP associative array. Since both have the same keys, only one will end up in your query. Do it like this instead:

                                "filter" => [
                                   [
                                     "terms" => [ 
                                        "Categories" => ['Featured Works']
                                     ]
                                   ],
                                   [
                                     "terms" => [
                                        "Tags" => ['Merida']
                                     ]
                                   ]
                                ]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 编写c++计算器,要求如下
  • ¥15 以下代码,运行结果报错
  • ¥15 Vivado仿真数据出错
  • ¥15 银河麒麟不支持vant等前端框架怎么办?
  • ¥15 vue3的子组件在父页面调用不显示不生效问题
  • ¥15 cadence PEX
  • ¥15 phython创建了文件 显示在项目下面,但运行不了,运行时还是运行main文件,并且说main文件不允许并行运行
  • ¥20 C++哈希表的设计构造哈希表
  • ¥15 FutureWarning:不推荐使用空或全 NA 条目的 DataFrame 串联行为。怎么改呢?
  • ¥15 Chatgpt突然无法正常显示数学公式,如何解决?