一、两种基本查询方式
1、REST请求URL
GET /bank/_search?q=*&sort=account_number:desc&pretty
2、REST请求体
GET /bank/_search
{
"query": { "match_all": {} },
"sort": [
{ "account_number": "desc" }
]
}
返回结果
{
"took" : 63,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : 1000,
"max_score" : null,
"hits" : [ {
"_index" : "bank",
"_type" : "_doc",
"_id" : "0",
"sort": [0],
"_score" : null,
"_source" : {"account_number":0,"balance":16623,"firstname":"Bradshaw","lastname":"Mckenzie","age":29,"gender":"F","address":"244 Columbus Place","employer":"Euron","email":"bradshawmckenzie@euron.com","city":"Hobucken","state":"CO"}
}, {
"_index" : "bank",
"_type" : "_doc",
"_id" : "1",
"sort": [1],
"_score" : null,
"_source" : {"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}
}, ...
]
}
}
说明:
took:Elasticsearch执行搜索消耗的时间(毫秒)
time_out:搜索是否超时
_shards:搜索了几个分片,成功、失败、略过了多少分片
hits:查询结果
hits.total:匹配查询条件的总文档数
hits.hits:查询结果(默认返回10条)
hits.sort:结果的排序键