脚本查询,语法跟版本有关,我是用的es是5.2.2
1. Exists Query
判断字段是否存在
POST schools/classes/_search
{
"query": {
"exists" : { "field" : "price" }
}
}
查询存在price字段的记录
效果
{
"took": 220,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "schools",
"_type": "classes",
"_id": "11",
"_score": 1,
"_source": {
"classes_id": 11,
"name": "班级11",
"address": "深圳市福田区福华路11",
"price": 11.4,
"timestamp": 1572573660000,
"users": [
{
"name": "SIMA",
"age": "11",
"price": 13.4
},
{
"name": "LIYAO",
"age": "13",
"price": 13.2
}
]
}
}
]
}
}
2. Sort
排序
查询数据,简单处理后返回,如下地址+ “hello”
POST schools/classes/_search
{
"query": {
},
"sort": [
{
"timestamp": {
"order": "desc"
}
}
]
}
效果
{
"took": 143,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 1,
"max_score": null,
"hits": [
{
"_index": "schools",
"_type": "classes",
"_id": "11",
"_score": null,
"_source": {
"classes_id": 11,
"name": "班级11",
"address": "深圳市福田区福华路11",
"price": 11.4,
"timestamp": 1572573660000,
"users": [
{
"name": "SIMA",
"age": "11",
"price": 13.4
},
{
"name": "LIYAO",
"age": "13",
"price": 13.2
}
]
},
"sort": [
1572573660000
]
}
]
}
}
项目推荐
IT-CLOUD :IT服务管理平台,集成基础服务,中间件服务,监控告警服务等。
IT-CLOUD-ACTIVITI6 :Activiti教程源码。博文在本CSDN Activiti系列中。
IT-CLOUD-ELASTICSEARCH :elasticsearch教程源码。博文在本CSDN elasticsearch系列中。
IT-CLOUD-KAFKA :spring整合kafka教程源码。博文在本CSDN kafka系列中。
IT-CLOUD-KAFKA-CLIENT :kafka client教程源码。博文在本CSDN kafka系列中。开源项目,持续更新中,喜欢请 Star~