当前位置:   article > 正文

ES常用基础语法——查询语法_es查询语法

es查询语法

ES常用操作

1、添加字段

PUT /索引名/_mapping
{
  "properties": {
    "businessid": {
      "type": "keyword"
    }
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2、查询某个字段必须存在

GET /索引名/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "auto_insurance_policy"
          }
        }
      ]
    }
  },"_source": ["name","credential_no","auto_insurance_policy"]
  , "size": 100
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

3、删除索引type为4的数据

POST /索引名/_delete_by_query
{
  "query": {
    "match": {
      "type": "4"
    }
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

4、删除索引

DELETE  /索引名
  • 1

5、多条件查询

GET /索引名/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "type": "2"
          }
        },
        {
          "match": {
            "lio": "edfcvwsd"
          }
        }
      ]
    }
  }
} 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

6、ES大于小于

gte是大于等于 gt是大于 lte是小于等于 lt是小于

GET /索引名/_search
{
"query": {
"range": {
"pt_dt": {
"gte": "2023-07-20"
      }
    }
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

7、查询索引中time字段长度大于20的值

GET 索引名/_search
{
"query": {
"bool": {
"filter": {
"regexp": {
"time": {
"value": ".{20,}"
          }
        }
      }
    }
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

8、ES添加别名的语法和查询别名的语法

POST /_aliases
{
"actions" : [
    { "add" : { "index" : "gfds", "alias" : "lzdsy" } },
    { "add" : { "index" : "jhgfd", "alias" : "lzdsy" } },
    { "add" : { "index" : "ytrew", "alias" : "lzdsy" } },
    { "add" : { "index" : "nbvc", "alias" : "lzdsy" } }
  ]
}

POST /_aliases
{
"actions" : [
    { "add" : { "index" : "qazxftrds", "alias" : "lzdsy" } }
  ]
}
GET lzdsy/_alias
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

9、LINUX中ES统计数据的命令

curl -XGET  -H "Content-Type: application/json" '29.16.132.20:80/1013_dwa_policy_summary_auto/_count' 
  • 1

10、ES插入数据

POST 索引名/_doc/1f573878273511dc13509f03c422095d
{
"key" : "1f573878273511dc13509f03c422095d",
"num" : "粤567891a",
"pt_date" : "2023-05-29"
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

11、超多条件查询

GET /索引名/_search
{
  "_source": [
    "timeEnd",
    "coverageCode"
  ],
  "from": 0,
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "quotationDate": {
              "gte": "2021-01-01",
              "lte": "2021-02-02"
            }
          }
        }
      ],
      "must": [
        {
          "term": {
            "telSalesmanCode": "22002202"
          }
        },
        {
          "term": {
            "deptGroupCode": "22002202"
          }
        },
        {
          "term": {
            "officeCode": "22002202"
          }
        },
        {
          "bool": {
            "should": [
              {
                "term": {
                  "qaz": "876543234567"
                }
              },
        {
          "term": {
            "edc": "22002202"
          }
        }
      ]
    }
  },
  "size": 20
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53

12、ES健康状态

curl http://192.168.28.11:80/_cat/health?v  
  • 1

查看分片

curl http://192.168.28.11:80/_cat/shards 
  • 1

13、分片丢失修复 重置分片

curl -XPOST  -H "Content-Type: application/json" '192.168.28.11:80/_cluster/reroute' -d '{
"commands": [
    {
"allocate_empty_primary": {
"index": ".kibana_task_manager_1",
"shard": 0,
"node": "node-222",
"accept_data_loss": true
      }
    }
  ]
}
'
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

14、检查字段是否已新增

GET 索引名/_mapping
  • 1

15、根据字段查询值

GET 索引名/_search
{
  "query": {
    "match": {
      "key": "00525cf74a78a9262c6f9ced1a5bb559"
    }
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/708417
推荐阅读
相关标签
  

闽ICP备14008679号