开发者学堂课程【ElasticSearch 入门精讲:通过 REST 请求体】学习笔记,与课程紧密连接,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/631/detail/10018
通过 REST 请求体
ES Rest 通过 REST 请求体
上述匹配所有数据可以改成如下写法
curl-XPOST ‘localhost:9200/bank/_search?pretty'-d '{"query”: {“match_all”:{}}}’
与第一种方式不同是在URI中替代传递q=* ,使用 POST 方式提交,请求体包含 JSON 格式搜索。
search?pretty'(访问的结果会格式化显示出来) -d(data的缩写)
查询 http://janson01:9200/bank/
_search?preety&q=* GET
提交请求后
{
"took": 33,
"timed_out": false,
"_shards": {
"total": 5,
"successful”: 5,
"skipped": 0 ,
"failed": 0
},
"hits": {
“total": 1000,
"max_score": 1 ,
"hits": [
{
“_index": "bank",
“_ type": "account",
“_id": "25",
“_score": 1,
“_source": {
“account_number": 25 ,
“balance": 40540,
"firstname": "Virginia”,
"lastname": "Ayala”,
"age": 39,
"gender": "F",
"address": "171 Putnam Avenue",
"employer": "Filodyne",
"email":
"virginlaayala@filodyne.com"
“city”:”Nicholson”,
"state": "PA"
}
}
,
{
“_index": "bank"
“_type": "account"
“_id": "44”,
“_score": 1,
“_source": {
"account_number": 44,
"balance": 34487,
"firstname": "Aurelia",
"lastname": "Harding”,
"age": 37,
"gender": "M",
"address": "502 Baycliff Terrace",
"employer": "Orbalix",
"email:
"aureliaharding@orbalix.com",
"city": "Yardville”,
"state": "DE"
}
查询
http://janson01:9200/bank/
_
search?preety POST
{"query”: {“match_all”:{}}}通过【验证 JSON 】格式化后
{
"query”: {
“match_all”: {}
}
提交请求后与上述效果相同(该方式为通过请求体)