elastic7 and or

作者:谢高升 发布:2021-07-30 浏览:471次

比如  create_time >16888888 and created<1788888 and ( toid ='aaa' or from_id='aaaaa')的预发

{
    "query":{
        "bool":{
            "must":{
                "match_all":{

                }
            },
            "filter":[
                {
                    "range":{
                        "create_time":{
                            "gt":1627574400,
                            "lt":1627616130
                        }
                    }
                },
                {
                    "bool":{
                        "should":[
                            {
                                "term":{
                                    "to_id":"89762"
                                }
                            },
                            {
                                "term":{
                                    "from_id":"89762"
                                }
                            }
                        ]
                    }
                },
                {
                    "range":{
                        "id":{
                            "gte":2736680
                        }
                    }
                }
            ]
        }
    },
    "sort":[
        {
            "id":{
                "order":"asc"
            }
        }
    ],
    "from":0,
    "size":10
}

PHP的代码如下

$query = [
    'bool'=>[
        'must'=>[
            'match_all'=>new \stdClass(),
        ]
    ],
];
$query['bool']['filter'][] = [
    'range'=>[
        'create_time'=>[
            'gt' => (int)$start_time , 'lt' =>(int)$end_time
        ]
    ]
];
if ($param['keyword']){
    $query['bool']['filter'][] = [
        'match_phrase'=>[
            'content'=>$param['keyword'],
        ],
    ];
}

$query['bool']['filter'][] = [
    'bool'=>[
        'should'=>[
            [
                'term'=>[
                    'to_id'=>$customerCode,
                ],
            ],
            [
                'term'=>[
                    'from_id'=>$customerCode,
                ],
            ]
        ]
    ]
];


标签: elastic and or
感谢博主,喝杯咖啡~