GET /索引库名/_search
{"query":{"bool":{"must":[{"match":{"title":"小米"}}],"should":[{"terms":{"price":["2699","2799"]}}]}}}
范围查询
价格大于等于2799 小于等于3899
GET /索引库名/_search
{"query":{"range":{"price":{"gte":2799,"lte":3899}}}}
模糊查询
标题为oppo 默认允许错误一个字母,最大为两个字母 正确标题 oppo
fuzziness:配置篇里
GET /索引库名/_search
{"query":{"fuzzy":{"title":{"value":"oope","fuzziness":2}}}}
过滤filter 不会影响查询的分数_score
GET /索引库名/_search
{"query":{"bool":{"must":[{"match":{"title":"小米"}}],"filter":[{"range":{"price":{"gte":2699,"lte":4999}}}]}}}
查询全部数据,如果数据很多,kibana默认只返回前10条数据
如果想一开始就设置的话,参考这篇文章 不然就在查询的时候,带上from和size这两个参数
## 查询所有
GET /poem/_search
{"from":0,"size":50,"query":{"match_all":{}}}
参考文章
八、排序
GET /索引库名/_search
{"query":{"bool":{"filter":[{"range":{"price":{"gte":2699,"lte":4999}}}]}},"sort":[{"price":{"order":"desc"}},{"_id":{"order":"asc"}}]}
PUT /cars
{"settings":{"number_of_shards":1,"number_of_replicas":0},"mappings":{"properties":{"color":{"type":"keyword"},"make":{"type":"keyword"}}}}
批量添加数据
POST /cars/_bulk
{"index":{}}{"price":10000,"color":"red","make":"honda","sold":"2014-10-28"}{"index":{}}{"price":20000,"color":"red","make":"honda","sold":"2014-11-05"}{"index":{}}{"price":30000,"color":"green","make":"ford","sold":"2014-05-18"}{"index":{}}{"price":15000,"color":"blue","make":"toyota","sold":"2014-07-02"}{"index":{}}{"price":12000,"color":"green","make":"toyota","sold":"2014-08-19"}{"index":{}}{"price":20000,"color":"red","make":"honda","sold":"2014-11-05"}{"index":{}}{"price":80000,"color":"red","make":"bmw","sold":"2014-01-01"}{"index":{}}{"price":25000,"color":"blue","make":"ford","sold":"2014-02-12"}
聚合为桶
GET /cars/_search
{"aggs":{"color":{"terms":{"field":"color"}}}}
桶内度量
GET /cars/_search
{"size":0,"aggs":{"color":{"terms":{"field":"color"},"aggs":{"avg_price":{"avg":{"field":"price"}}}}}}
桶内嵌套桶
GET /cars/_search
{"size":0,"aggs":{"color":{"terms":{"field":"color"},"aggs":{"avg_price":{"avg":{"field":"price"}},"mark":{"terms":{"field":"make"}}}}}}
阶梯分组 对价格进行阶梯分组,最小数量为1才显示
GET /cars/_search
{"size":0,"aggs":{"price_histogram":{"histogram":{"field":"price","interval":5000,"min_doc_count":1}}}}
范围分组
GET /cars/_search
{"size":0,"aggs":{"price_range":{"range":{"field":"price","ranges":[{"from":5000,"to":15000},{"from":15000,"to":20000},{"from":20000,"to":25000},{"from":25000,"to":35000},{"from":35000,"to":40000}]}}}}