# Es查询表达式(Query DSL)

Es查询表达式(Query DSL)


精确值查找
  1. terms查询(包含查询,类似与sql的in)
{
  "query":{
    "terms":{
      "id":["1001","1002"]
    } 
  }
}
  1. term查询
select * from test where name ='test'
{
    "query":{
        "term":{
            "naem":{
                "value":"test"
            }
        }
    }
}
bool过滤器
  1. bool过滤器组成部分
{
    "bool":{
    	//与And等价
        "must":[]
        //与Or等价
        "should":[]
        //与not等价
       	"must_not":[]
       	//必须匹配
       	"filter":[]
    }
}
范围检索
  1. range query
gt:>大于(greather than)
lt:<小于(less than)
gte:>大于或者等于(greather than or equal to)
lte:<小于或者等于(less than or equal to)

相当与sql

select * from test where 1=1 and age>=10 and age<=20 
{
    "query":{
        "bool":{
            "must":{
                "range":{
                    "age":{
                        "gte":10,
                        "lte":20
                    }
                }
            }
        }
    }
}
  1. 匹配查询
select * from test where 1=1 and age>=10 and age<=20  and name like'%test%'
select * from test where 1=1 and age>=10 and age<=20  and name in'test1','test2')
{
  "query":{
    "bool":{
        "must":{
        "range":{
          "es_time":{
            "gte": "2019-07-03 00:00:00",
            "lte": "2019-07-03 23:59:59"
          }
        }
      },
      "filter":{
        "terms":{
          //匹配查询
          "name":["test"]
          //精确查询
          "name.keyword":["test1","test2"]
        }
      }
    }
  }
}
前缀检索
  1. prefix query匹配前缀:类似与sql的like ‘%test’
{
    "query":{
        "prefix":{
            "name":{
                "value":"玲"
            }
        }
    }
}
  1. 通配符匹配
{
    "query":{
        "wildcard":{
            "name":{
                "value":"玲*"
            }
        }
    }
}
模糊检索
{
    "query":{
        "fuzzy":{
            "name":{
                "value":"阿"
            }
        }
    }
}
聚合功能
  1. 类似于sql中的group by可以进行聚合统计
{
    "aggs":{
        "all_name":{
            "terms":{"filed":"name"}
        }
    }
}
  1. 加上where 条件:统计姓名中含有勇,并且根据姓名Group by
{
    "query":{
        "match":{
            "name":"勇"
        }
    },
    "aggs":{
        "all_names":{
            "terms":{"files":"name"}
        }
    }
}
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

全栈程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值