赞
踩
中文官网网站:
https://www.elastic.co/guide/cn/elasticsearch/guide/current/_retrieving_a_document.html
(基于2.X版本) 7.X版本以后,不再需要类型字段插叙 了
集群健康查询:
curl -XGET 'http://IP:9200/_cluster/health?pretty'
全量查询:
curl -H "Content-Type: application/json" 'http://IP:9200/_count' -d '{"query":{"match_all":{}}}'
关键字查询:
- curl -H "Content-Type: application/json" 'http://IP:9200/index_name/type1/_search' -d '{
- "query": {
- "bool": {
- "must": [
- {
- "match": {
- "dutyName": {
- "query": "任务名称5169"
- }
- }
- }
- ]
- }
- },
- "from": 0,
- "size": 1
- }'
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
指定文档ID搜索:
curl -H "Content-Type: application/json" 'http://ip:9200/test2/type1/YGKWinoB-a2t_Il3fi3i?pretty'
使用表达式查询
- curl -H "Content-Type: application/json" 'http://ip:9200/test2/type1/_search' -d '{
- "query":{
- "match":{
- "dutyId":982
- }
- }
- }'
条件查询
- curl -H "Content-Type: application/json" 'http://ip:9200/_search?pretty' -d '{
- "query" : {
- "bool": {
- "must": {
- "match" : {
- "dutyName" : "任务名称5169"
- }
- },
- "filter": {
- "range" : {
- "talkTime" : { "gt" : 96}
- }
- }
- }
- }
- }'
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
精确匹配 短语搜索:
- {
- "query" : {
- "match_phrase" : {
- "about" : "rock climbing"
- }
- }
- }
高亮匹配:在每个搜索结果中 高亮 部分文本片段,以便让用户知道为何该文档符合查询条件
- curl -H "Content-Type: application/json" 'http://ip:9200/_search?pretty' -d '{
- "query" : {
- "bool": {
- "must": {
- "match" : {
- "dutyName" : "任务名称5169"
- }
- },
- "filter": {
- "range" : {
- "talkTime" : { "gt" : 96}
- }
- }
- }
- },
- "highlight": {
- "fields" : {
- "dutyName" : {}
- }
- }
- }'
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
当执行该查询时,返回结果与之前一样,与此同时结果中还多了一个叫做 highlight
的部分。这个部分包含了 about
属性匹配的文本片段,并以 HTML 标签 <em></em>
封装。
- {
- "_index" : "agg_duty_test3",
- "_type" : "type1",
- "_id" : "sEdjmHoBlchvgIdDKWe2",
- "_score" : 0.024813946,
- "_source" : {
- "id" : 19022,
- "dutyId" : 22,
- "dutyName" : "任务名称8779",
- "flowId" : "0c27Oi94JxzKxYb0id8z",
- ...
- "area" : "0c27Oi94Jx",
- "businessType" : "0c27Oi94JxzKxYb0id8zpQ1ZINXnMR",
- "phoneNum" : "17847507165"
- },
- "highlight" : {
- "dutyName" : [
- "<em>任</em><em>务</em><em>名</em><em>称</em>8779"
- ]
- }
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
根据日期格式删除es数据:
- # ES 7.X以后废弃了 type
- curl -H "Content-Type: application/json" 'http://172.31.63.15:9200/index_name/_delete_by_query' -d '{
- "query":{
- "range":{
- "payDate":{
- "lt": "2021-06-26",
- "format":"yyyy-MM-dd"
- }
- }
- }
- }'
根据日期条件查询数据
- curl -H "Content-Type: application/json" 'http://172.31.63.15:9200/index_name/_search' -d '{
- "query":{
- "range":{
- "payDate":{
- "lt": "2021-06-26",
- "format":"yyyy-MM-dd"
- }
- }
- }
- }'
待补充整理。。。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。