为帖子数据增加浏览量的字段
#插入展示数量
POST /post/_doc/_bulk
{ "update": { "_id": "1"} }
{ "doc" : {"view_cnt" : 30} }
{ "update": { "_id": "2"} }
{ "doc" : {"view_cnt" : 50} }
{ "update": { "_id": "3"} }
{ "doc" : {"view_cnt" : 100} }
{ "update": { "_id": "4"} }
{ "doc" : {"view_cnt" : 80} }
搜索浏览量在30~60之间的帖子
GET /post/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"view_cnt": {
"gt": 30,
"lt": 60
}
}
}
}
}
}
搜索发帖日期在最近1个月的帖子
#指定日期前30天数据
GET /post/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"postDate": {
"gte": "2017-02-01||-30d"
}
}
}
}
}
}
#当前时间减30天数据
GET /post/_search
{
"query": {
"constant_score": {
"filter": {
"range": {
"postDate": {
"gte": "now-30d"
}
}
}
}
}
}