比如 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, ], ] ] ] ];