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

ES常用操作

1、添加字段

PUT /索引名/_mapping
{
  "properties": {
    "businessid": {
      "type": "keyword"
    }
  }
}

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

GET /索引名/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "auto_insurance_policy"
          }
        }
      ]
    }
  },"_source": ["name","credential_no","auto_insurance_policy"]
  , "size": 100
}

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

POST /索引名/_delete_by_query
{
  "query": {
    "match": {
      "type": "4"
    }
  }
}

4、删除索引

DELETE  /索引名

5、多条件查询

GET /索引名/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "match": {
            "type": "2"
          }
        },
        {
          "match": {
            "lio": "edfcvwsd"
          }
        }
      ]
    }
  }
} 

6、ES大于小于

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

GET /索引名/_search
{
"query": {
"range": {
"pt_dt": {
"gte": "2023-07-20"
      }
    }
  }
}

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

GET 索引名/_search
{
"query": {
"bool": {
"filter": {
"regexp": {
"time": {
"value": ".{20,}"
          }
        }
      }
    }
  }
}

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

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

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

10、ES插入数据

POST 索引名/_doc/1f573878273511dc13509f03c422095d
{
"key" : "1f573878273511dc13509f03c422095d",
"num" : "粤567891a",
"pt_date" : "2023-05-29"
}

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
}

12、ES健康状态

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

查看分片

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

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
      }
    }
  ]
}
'

14、检查字段是否已新增

GET 索引名/_mapping

15、根据字段查询值

GET 索引名/_search
{
  "query": {
    "match": {
      "key": "00525cf74a78a9262c6f9ced1a5bb559"
    }
  }
}

你可能感兴趣的:(大数据,elasticsearch,大数据,搜索引擎)