带有术语查询的弹性搜索和条件

时间:2016-09-09 09:59:54

标签: elasticsearch querydsl

这是我的搜索过滤器查询, 我想给出条款的“和”条件。 现在我已经在过滤条件中给出了必须

'query' => [
    "filtered" => [
        "query" => [
            "match_all" => []
        ],
        "filter" => [
            "bool" => [
                "must" => [
                    "terms" => [
                        "num" => [
                            1,2,3
                        ]
                    ],
                    "terms" => [
                        "sample" => [
                            "a", "b"
                        ],
                    ]
                ]
            ]
        ],
        'query' => [
            'multi_match' => [
                'query' => "Hello",
                'fields' => ['text'],
                'operator' => 'and'
            ],
        ]
    ]
],

但它不起作用。还有其他解决办法吗?

2 个答案:

答案 0 :(得分:1)

尝试这一点,当你想添加'和'condtion时,只需在bool中添加该部分即可。

{"query":{"bool":{"must":[{"terms":{"num":[1,2,3]}},{"terms":{"sample":["a","b"]}},{"match":{"text":"hello"}}]}},"from":0,"size":10}

答案 1 :(得分:0)

您需要将Snackbar.make()个过滤器放在另一个数组中,否则您的terms会变成一个关联数组,而这不是您想要的(即bool/must过滤器中的一个被丢弃)

terms