Zakariyya / blog

https://zakariyya.github.io/blog/
6 stars 1 forks source link

Kibana在 Dev tools 中的基础查询语法,版本 8.11.1 (elasticsearch) #165

Open Zakariyya opened 7 months ago

Zakariyya commented 7 months ago
# Click the Variables button, above, to create your own variables.
GET _search
{
  "query": {
    "match_all": {}
  }
}

## 查看索引
GET _cat/indices?v

##创建索引
PUT /products

## 创建索引
PUT /orders
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

## 删除某个索引
DELETE /products

# 创建商品索引,products指定 mapping{id,title,price,created_at,description}
PUT /products
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "id":{
        "type":"integer"
      },
      "title":{
        "type": "keyword"
      },
      "price":{
        "type": "double"
      },
      "description":{
        "type": "text"
      }
    }
  }

}

## 查看某个索引的映射
GET /products/_mapping

######################################

## 添加文档 手动指定id
## 如果重复操作其实就是变成更新(update),注意:底层操作是将旧数据删除,然后填入新数据,所以es的更新是一个全量更新
POST /products/_doc/1
{
  "id":1,
  "title":"iphone13",
  "price":5900.0,
  "description":"iphone13真香,十三香-1"
}

## 添加文档 自动创建文档的id 
POST /products/_doc/
{
  "id":1,
  "title":"iphone13",
  "price":5900.0,
  "description":"iphone13真香,十三香"
}

## 文档查询 基于id查询
GET /products/_doc/afzqC4wBSpW174iq0txn
GET /products/_doc/1

## 删除文档 基于id删除
DELETE /products/_doc/afzqC4wBSpW174iq0txn

## 更新文档:如果重复操作其实就是变成更新(update),注意:底层操作是将旧数据删除,然后填入新数据,所以es的更新是一个全量更新
PUT /products/_doc/1
{
  "description":"iphone13真香,十三香"
}

## 更新文档 基于指定字段进行更新
## 但实际操作是报错的
POST /products/_doc/1/_update
{
  "doc":{
    "price":1.6
  }
}

## 更新文档 基于指定字段进行更新
## 这个实际操作没问题,是gpt提供的
POST /products/_update/1
{
  "script": {
    "source": "ctx._source.price = params.new_price",
    "lang": "painless",
    "params": {
      "new_price": 1.6
    }
  }
}

################################

## 文档批量操作 _bulk
POST /products/_doc/_bulk
{"index":{"_id":2}}
  {"id": 2, "title": "iphone14", "price": 1.6, "description": "iphone14真香,香-4"}
{"index":{"_id":3}}
  {"id": 3, "title": "iphone15", "price": 1.6, "description": "iphone15真香,香-5"}

## 分词器测试
POST /_analyze
{
  "analyzer":"ik_smart",
  "text":"中华人民共和国国歌"
}

POST /_analyze
{
  "analyzer":"ik_max_word",
  "text":"南极人1加5T国国歌"
}
Zakariyya commented 7 months ago
## 深度分页的做法
GET /material/_search
{
  "query": {
    "match_all": {}
  },
  "from": 0,
  "size":200000,

 "sort": [
    {
      "_id": {
        "order": "desc"
      }
    }
  ],
  "search_after": [908840730254901251]
}
Zakariyya commented 7 months ago
## 配置单页最大页数
PUT material/_settings
{
  "index": {
    "max_result_window": 100000
  }
}