1、query string search
GET /index/type/_search?q=field:xxx&sort=field:desc
适合用于临时的在命令行使用一些工具,比如curl,快速的发出请求来检索想要的信息;但是如果查询请求很复杂,是很难去构建的,在生产环境中几乎很少使用。
2、query DSL
1)、全剖查询
GET /index/type/_search
{
"query":{
"match_all":{
}
}
}
2)、匹配字段查询、排序、分页
GET /index/type/_search
{
"query":{
"match": {
"name": "红"
}
},
"sort":[{
"age":"desc"
}]
"from":0,
"size":2
}
3)、查询特定字段
GET /index/type/_search
{
"query":{
"match": {
"name": "红"
}
},
"_source": ["name","age"]//要查询的特定字段数组
}
4)、必须匹配要查询的值,以及过滤查询
GET /index/type/_search
{
"query": {
"bool": {
"must": [
{"match": {
"name": "红"
}
}
],
"filter": {
"range": {
"age": {
"gt": 25
}
}
}
}
}
}
5)、要查询的字段全部匹配要查询的值以及高亮显示
GET /index/type/_search
{
"query": {
"match_phrase": {
"desc": "小明 学生"
}
},
"highlight": {
"fields": {
"desc": {}
}
}
}