Elasticsearch查询语法
es常用查询
term 项
例: 搜 Dahlen, Malone
$filter[] = ['term' => ['ename' => 'accountcreate']]; $filter[] = ['term' => ['app_id' => 1000084]];
field 字段
field:value 例:city:Keyport, age:26
通配符
? 匹配单个字符 例: H?bbs
* 匹配0到多个字符 例: H*
注意: ? * 不能用作第一个字符,例如: ?text *text
范围查询
age:[20 TO 30] age:{20 TO 30}
注:[ ] 表示端点数值包含在范围内,{ } 表示端点数值不包含在范围内
$filter[] = [ 'range' => [ '@timestamp' => [ 'gte' => $start_time, 'lt' => $end_time, 'format' => 'epoch_second', ], ], ];
排序
$params['sort'] = [ ['@timestamp' => ['order' => 'asc']], ];
逻辑操作
AND OR 例子:firstname:H* AND age:20 firstname:H* OR age:20
+ :搜索结果中必须包含此项
- :不能含有此项
例: +firstname:H* -age:20 city:H* firstname字段结果中必须存在H开头的,不能有年龄是20的,city字段H开头的可有可无
分组
(firstname:H* OR age:20) AND state:KS 先查询名字H开头年龄或者是20的结果,然后再与国家是KS的结合
字段分组
firstname:(+H* -He*) 搜索firstname字段里H开头的结果,并且排除firstname里He开头的结果
转义特殊字符
+ - && || ! () {} [] ^" ~ * ? : \
注意:以上字符当作值搜索的时候需要用 \ 转义
参考:https://blog.csdn.net/hu948162999/article/details/51258257
参考:https://blog.csdn.net/sinat_36005594/article/details/90449781
https://blog.csdn.net/u013473512/article/details/78163775
https://blog.csdn.net/weixin_43865381/article/details/97904321