// 查询 按照 id desc
// size 每页显示 数目
$curl_param = [
'sort'=>[
'id'=>[
'order'=>$sort
]
],
'size'=>$size
];
// range 范围查询
$curl_param = [
'sort'=>[
'id'=>[
'order'=>$sort
]
],
'size'=>$size,
'query'=>[
'bool'=>[
'must'=>[
'range'=>[
'id'=>[
'gt'=>$rand_id
]
]
]
]
]
];
// term 使用 等价于 sql where id=3 的形式
$curl_param = [
'sort'=>[
'id'=>[
'order'=>'desc'
]
],
'size'=>$size,
'query'=>[
'term'=>[
'platform'=>$platform
]
]
];
// bool 集合查询
// fuzzy 模糊查询 等价于 %%
$curl_param = [
'sort'=>[
'id'=>[
'order'=>'desc'
]
],
'size'=>$size,
'query'=>[
'bool'=>[
'must'=>[
[
'term'=>[
'type'=>$type
]
],
[
'term'=>[
'platform'=>$platform
]
]
],
'should'=>[
[
'fuzzy'=>[
'title'=>[
'value'=>$param
]
]
],
[
'fuzzy'=>[
'domain'=>[
'value'=>$param
]
]
]
]
]
]
];
// max min 查询
$curl_param = [
'query'=>[
'bool'=>[
'must'=>[
'term'=>[
'id'=>$id
]
]
]
],
'aggs'=>[
'first_detected'=>[
'min'=>[
'field'=>'created_date'
]
],
'last_detected'=>[
'max'=>[
'field'=>'created_date'
]
]
]
];
// groub By 查询
// group_by_state
$curl_param = [
'query'=>[
'bool'=>[
'must'=>[
[
'term'=>[
$isfield=>1
]
],
[
'term'=>[
'host'=>$host
]
]
]
]
],
'aggs'=>[
'group_by_state'=>[
'terms'=>[
'field'=>$field
]
]
]
];
//多字段查询
$curl_param = [
'sort'=>[
'id'=>[
'order'=>'desc'
]
],
'query'=>[
'multi_match'=>[
'query'=>$title,
'type'=>'best_fields',
'fields'=>[
'title','domain','keywords'
],
'tie_breaker'=>0.3,
'minimum_should_match'=>'30%'
]
]
];
// filter 过滤 使用
$curl_param = [
'sort'=>[
'id'=>'desc'
],
'query'=>[
'filtered'=>[
'filter'=>[
'range'=>[
'id'=>[
'gte'=>$min_id,
'lte'=>$max_id
]
]
]
]
]
];
$curl_param = [
'sort'=>[
'id'=>[
'order'=>'desc'
]
],
'size'=>$size,
'query'=>[
'bool'=>[
'must'=>[
[
'fuzzy'=>[
'title'=>$param
]
],
[
'term'=>[
'type'=>$type
]
],
[
'term'=>[
'platform'=>$platform
]
],
[
'term'=>[
'shape'=>$shape
]
],
[
'range'=>[
'created_date'=>[
'gte'=>$startTime,
'lt'=>$endTime
]
]
],
[
'range'=>[
'id'=>[
'gte'=>$last_id
]
]
]
]
]
]
];
// should 使用
//
foreach ($param as $key => $value) {
if($value)
{
$should_arr[] = [
'term'=>[
'id'=>$value
]
];
}
}
$curl_param = [
'query'=>[
'bool'=>[
'should'=>$should_arr
]
]
];
es 学习 3 DSL 总结
最新推荐文章于 2024-06-20 13:52:27 发布