elasticsearch 查询语法

  • match_all 查询所有
GET test/_search
{
  "query": {
    "match_all": {}
  }
}
  • match 单字段匹配查询
GET test/_search
{
  "query":{
    "match":{
      "name":"zhangsan"
    }
  }
}
  • multi_match 多字段匹配查询
GET test/_search
{
  "query":{
    "match":{
      "name":"zhangsan"
    }
  }
}
  • term 关键字精确查询
GET test/_search
{
	"query": {
		"term": {
			"name": {
				"value": "zhangsan"
			}
		}
	}
}
  • terms 多关键字精确查询
GET test/_search
{
	"query": {
		"terms": {
			"status": {
				"value": [0,1,2,3]
			}
		}
	}
}
  • fuzzy 模糊匹配选择展示指定字段
GET test/_search
{
  "query": {
    "fuzzy": {
      "data": "好"
    }
  },
   "_source": ["name", "data"]
}
  • 过滤字段
    • includes:来指定想要显示的字段
    • excludes:来指定不想要显示的字段
GET test/_search
{
  "query": {
    "terms": {
      "nickname": ["zhangsan"]
    }
  },
  "_source": {
    "includes": ["name","nickname"
    ]
  }
}
  • exists 查询字段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"],
  "sort": [
    {
      "customer_gmt_create_time": {
        "order": "asc"
      }
    }
  ],
  "from": 0,
  "size": 10
}
  • match_phrase_prefix 前缀查询
GET test/_search
{
  "query": {
    "match_phrase_prefix": {
      "name": "wang"
    }
  }
}
  • 指定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"],
  "sort": [
    {
      "customer_gmt_create_time": {
        "order": "asc"
      }
    }
  ],
  "from": 0,
  "size": 10
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值