- 如何使用es 实现 sql 中的>= and <=
- 1、range,sql中的between,或者是>=1,<=1
- 2、range做范围过滤
1.搜索浏览量在30~60之间的帖子
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"view_cnt": {
"gt": 30,
"lt": 60
}
}
}
}
}
}
- gte 大等于
- lte 小等于
2.搜索发帖日期在最近1个月的帖子。
方式一
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"postDate": {
"gt": "2017-03-10||-30d"
}
}
}
}
}
}
方式二
使用now
GET /forum/article/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"postDate": {
"gt": "now-30d"
}
}
}
}
}
}