• 查询对应索引下所有数据(match_all)
GET test/_search
{
"query": {
"match_all": {}
}
}
  • 单字段查询,不能多字段组合查询(match)
GET test/_search
{
"query":{
"match":{
"name":"zhangsan"
}
}
}
  • 模糊匹配选择展示指定字段
GET test/_search
{
"query": {
"fuzzy": {
"data": "好"
}
},
"_source": ["name", "data"]
}
  • 查询字段age存在且id等于45的数据
GET /test/_search
{
"query": {
"bool": {
"must": [
{
"exists": {
"field": "age"
}
},
{
"term": {
"id": {
"value": 45
}
}
}
]
}
}
}
  • 组合查询
GET /test/_search
{
"query": {
"bool": {
"must": [
{
"terms": {
"is_success": [1,2]
}
},
{
"term": {
"deleted": 0
}
}
]
}
},
"_source": [
"_id",
"name",
"stage"
],
"from": 0,
"size": 1000
}
  • 排序+分页
GET test/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"customer_gmt_create_time": {
"order": "asc"
}
}
],
"from": 0,
"size": 10
}
  • match_phrase_prefix
GET test/_search
{
"query": {
"match_phrase_prefix": {
"name": "wang"
}
}
}
  • 查找多个精确值(terms)
GET test/_search
{
"query": {
"bool": {
"should": [
{
"term": {
"age":27
}
},{
"term":{
"age":28
}
}
]
}
}
}
  • 指定id批量查询
GET test/_search
{
"query": {
"ids": {
"values": ["66606794","66606795"]
}
}
}
  • 组合查询(range+should)
GET test/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"create_time": {
"gte": "2017-12-25 01:25:10",
"lte": "2017-12-25 12:10:36"
}
}
},
{
"bool": {
"should": [
{
"term": {
"name": {
"value": "zhangsan"
}
}
},
{
"term": {
"age": {
"value": 7
}
}
}
]
}
}
]
}
},
"_source": ["alarm_name","alarm_time","alarm_type","info"]
}