五、POST查询
然后调用下方下方的请求则是一个简单的数据查询请求:
请求方式:POST
URL:http://192.168.1.199:9200/_search?index=megacorp&type=employee
Header:Content-Type:application/json
Body:
{
"from": 0,
"size": 10,
"query": {
"term": {
"age": {
"value": 30,
"boost": 1.0
}
}
},
"sort": [{
"birthday": {
"order": "desc"
}
}]
}
请求说明:
URL:_search/?index=megacorp&type=employee 分别为 {查询方式}?index={索引名称}&type={文档名称} 这里的索引名称与文档名称可以不填写,但是如果不填写则会连带其他索引和文档一起进行查询,建议填写。
Body:
{
"from-查询的开始位置": 0,
"size-查询结果数量": 10,
"query-查询条件,可以不填": {
"term-查询条件,后面会有详细说明": {
"age-字段名": {
"value-值": 30
}
}
},
"sort-排序": [{
"birthday-排序字段名": {
"order-排序方式": "desc-倒序"
}
}]
}
之后会获取到服务器的响应数据:
{
"took": 0,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": null,
"hits": [
{
"_index": "megacorp",
"_type": "employee",
"_id": "1",
"_score": null,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 30,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
],
"birthday": "1989-02-02"
},
"sort": [
602380800000
]
},
{
"_index": "megacorp",
"_type": "employee",
"_id": "2",
"_score": null,
"_source": {
"first_name": "Jack",
"last_name": "Ma",
"age": 30,
"about": "I regret having founded alibaba",
"interests": [
"speech"
],
"birthday": "1989-01-01"
},
"sort": [
599616000000
]
}
]
}
}