Fork me on GitHub

ES学习(一)

冲冲冲

索引


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

# 创建索引
PUT /products

PUT /orders
{
  "settings": {
    "number_of_shards": 1, 
    "number_of_replicas": 0
  }
}

DELETE /products

# 索引不允许修改

映射


PUT /products
{
  "settings": {
    "number_of_shards": 1, 
    "number_of_replicas": 0
  },
  "mappings": {
    "properties": {
      "id": {
        "type": "integer"
      },
      "title": {
        "type": "keyword"
      },
      "price": {
        "type": "double"
      },
      "created_at": {
        "type": "date"
      },
      "description": {
        "type": "text"
      }
    }
  }
}

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

# 映射不允许修改

文档


# 添加文档操作 手动操作 _id
POST /products/_doc/1
{
  "id": 1,
  "title": "小浣熊",
  "price": 0.5,
  "created_at": "2021-11-12",
  "descriptin": "小浣熊真好吃"
}

#   IsdFLX4BxnEQK7xX975G
POST /products/_doc/
{ 
  "title": "日本豆",
  "price": 1.5,
  "created_at": "2021-11-12",
  "descriptin": "日本豆真好吃"
}

# 文档查询  根据id
GET /products/_doc/1

# 删除文档
DELETE /products/_doc/1

# 更新文档 这种方式会先删除原始文档,再重新添加
PUT /products/_doc/1
{
  "title": "小浣熊熊"
}

# 更新文档,基于指定字段进行更新
POST /products/_doc/1/_update
{
  "doc": {
    "title": "大熊猫"
  }
}

批量操作


# 批量索引两条文档   ?删除再添加?会覆盖
POST /products/_doc/_bulk
{"index":{"_id":"2"}}
{"title":"iphone14","price":"8999.99","created_at":"2021-09-15","description":"iphone 14 哒哒da哒"}
{"index":{"_id":"3"}}
{"title":"iphone15","price":"11111","created_at":"2021-09-15","description":"iphone15 还没出"}

# 添加 更新 删除  {update->doc}先查出来再更新,不会覆盖
POST /products/_doc/_bulk
{"index":{"_id":4}}
{"id":4,"title":"iphone166","created_at":"2022-11-12","description":"太久远了"}
{"update":{"_id":3}}
{"doc":{"title":"更新后的15"}}   
{"delete":{"_id":1}}
posted @ 2022-01-05 09:35  myboran  阅读(115)  评论(0)    收藏  举报