elasticsearch布尔查询添加逻辑

时间:2019-06-04 10:55:20

标签: elasticsearch

$params = [
        "size" => 5000,
        'index' => 'my_post',
        'type' => 'my_post',
        'body' => [
            'query' => [
                'bool' => [
                    'should' => [
                        [

                            'match' => ['poststatus_id' => 'public']
                        ],
                        [
                            "bool" => [
                                "must" => [
                                    "match" => [
                                        'poststatus_id' => 'only_me',
                                    ],
                                    "match" => [
                                        'creator.user_id' => $user
                                    ]
                                ]
                            ]


                        ],
                    ],
                ]
            ]
        ]
    ];

它是我的弹性搜索查询,我需要另一个或条件是 poststatus_id =“ followers”和creator.user_id(1,2,3,4) 有人告诉我如何编写此查询

2 个答案:

答案 0 :(得分:1)

尝试一下。

$params = [
        "size" => 5000,
        'index' => 'my_post',
        'type' => 'my_post',
        'body' => [
            'query' => [
                'bool' => [
                    'should' => [
                        [

                            'match' => ['poststatus_id' => 'public']
                        ],
                        [
                            "bool" => [
                                "must" => [
                                    [
                                        "match" => [
                                            'poststatus_id' => 'only_me',
                                        ]
                                    ],
                                    [
                                        "match" => [
                                            'creator.user_id' => $user
                                        ]
                                    ]
                                ]
                            ]
                        ],
                        [
                            "bool" => [
                                "must" => [
                                    [
                                        "match" => [
                                            "poststatus_id" => "followers"
                                        ]
                                    ],
                                    [
                                        "terms" => [
                                            "poststatus_id" => [1,2,3,4]
                                        ]
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ];

答案 1 :(得分:0)

 axios.post(`${baseApiUrl}/checkoutPayPal`, transaction)
                .then(res => window.location.replace(res.data))