term 过滤
term主要用于精确匹配哪些值,比如数字,日期,布尔值或 not_analyzed 的字符串(未经分析的文本数据类型):
{ "term": { "age": 26 }}
{ "term": { "date": "2014-09-01" }}
{ "term": { "public": true }}
{ "term": { "tag": "full_text" }}
完整的例子, hostname 字段完全匹配成 saaap.wangpos.com 的数据:
{
"query": {
"term": {
"hostname": "saaap.wangpos.com"
}
}
}
terms 过滤
terms 跟 term 有点类似,但 terms 允许指定多个匹配条件。 如果某个字段指定了多个值,那么文档需要一起去做匹配:
{
"terms": {
"tag": [ "search", "full_text", "nosql" ]
}
}
完整的例子,所有http的状态是 302 、304 的, 由于ES中状态是数字类型的字段,所有这里我们可以直接这么写。:
{
"query": {
"terms": {
"status": [
304,
302
]
}
}
}
range 过滤
range过滤允许我们按照指定范围查找一批数据:
{
"range": {
"age": {
"gte": 20,
"lt": 30
}
}
}
范围操作符包含:
- gt :: 大于
- gte:: 大于等于
- lt :: 小于
- lte:: 小于等于
一个完整的例子, 请求页面耗时大于1秒的数据,upstream_response_time 是 nginx 日志中的耗时,ES中是数字类型。
{
"query": {
"range": {
"upstream_response_time": {
"gt": 1
}
}
}
}
参考博客: https://www.cnblogs.com/ghj1976/p/5293250.html