首页 > 代码库 > Elasticsearch按请求体基本查询

Elasticsearch按请求体基本查询

1 分页:

localhost:9200/get-together/_search   

{
"query": {
"match_all": {}
},
"from": 10,
"size": 10
}

2 查询具体字段:

localhost:9200/get-together/_search

{
"query": {
"match_all": {}
},
"_source": ["name", "date"]
}

在指定字段时,你甚至可以使用通配符,比如你要查询name和nation,只要写na*就行了;你也可以指定你不想要返回的字段 "exclude": ["location.geolocation"],想要返回的字段:"include": ["location.*", "date"]。

3 排序:

 如果没有指定任何排序的信息,es默认按照_score降序排序,score其实就是每个文档与你查询的匹配度。

自定义排序 :localhost:9200/get-together/_search

{
"query": {
"match_all": {}
},
"sort": [
{"created_on": "asc"},
{"name": "desc"},
"_score"
]
}

 

4 同时运用以上三个的完整查询:localhost:9200/get-together/group/_search

{
"query": {
"match_all": {}
},
"from": 0,
"size": 10,
"_source": ["name", "organizer", "description"],
"sort": [{"created_on": "desc"}]
}

 

Elasticsearch按请求体基本查询