- 请求路径
GET /test1/_search?q=name:jack
- 请求体
GET /test1/_search
{
"query": {
"match": {
"name": "jack"
}
}
}
- 全量查询
GET /test1/_search
{
"query": {
"match_all": {}
}
}
- 分页查询
GET /test1/_search
{
"query": {
"match_all": {}
},
"from": 0,
"size": 2
}
- 按字段查询
GET /test1/_search
{
"query": {
"match_all": {}
},
"from": 0,
"size": 2,
"_source": ["name"]
}
- 排序查询
GET /test1/_search
{
"query": {
"match_all": {}
},
"from": 0,
"size": 20,
"_source": ["name"],
"sort": [
{
"age": {
"order": "desc"
}
}
]
}
7.多条件查询
GET /book/_doc/_search
{
"query": {
"bool": {
must 或 "should": [
{
"match": {
"title": "结构功能一体化复合材料技术"
}
},
{
"match": {
"title": "哈哈"
}
}
]
}
},
"from": 0,
"size": 10,
"_source": ["title"],
"sort": [
{
"id": {
"order": "asc"
}
}
]
}
8.范围查询
GET /book/_doc/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"title": "材料"
}
},
{
"match": {
"title": "哈哈"
}
}
],
"filter":{
"range":{
"id":{
"gt":5000
}
}
}
}
},
"from": 0,
"size": 10,
"_source": ["title"],
"sort": [
{
"id": {
"order": "asc"
}
}
]
}
- 高亮
GET /book/_doc/_search
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"title": "问题"
}
}
],
"filter":{
"range":{
"id":{
"gt":5000
}
}
}
}
},
"highlight":{
"fields":{
"title":{}
}
},
"from": 0,
"size": 10,
"_source": ["id","title"],
"sort": [
{
"id": {
"order": "asc"
}
}
]
}