本文共 1263 字,大约阅读时间需要 4 分钟。
POST /forum/article/_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} }
GET /forum/article/_search{ "query": { "constant_score": { "filter": { "range": { "view_cnt": { "gt": 30, "lt": 60 } } } } }}
3、搜索发帖日期在最近1个月的帖子。
POST /forum/article/_bulk{ "index": { "_id": 5 }}{ "articleID" : "DHJK-B-1395-#Ky5", "userID" : 3, "hidden": false, "postDate": "2017-03-01", "tag": ["elasticsearch"], "tag_cnt": 1, "view_cnt": 10 }
方式一
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" } } } } }}
转载地址:http://zeonn.baihongyu.com/