Elasticsearch operation (command mode)

Description: elasticsearch is currently the most popular search engine, powerful and very popular. The feature is the inverted index, which is very efficient in the field of fuzzy search for massive data. Elasticsearch installation and usage reference: http://t.csdn.cn/yJdZb.

This article introduces the index library (index) operation and document (document) operation in es, which is equivalent to the table operation and data operation of the database.

Index library (index) operations

Create an index library

Format: PUT /index library name

PUT /student
{
    
    
  # 映射,索引中文档的约束
  "mappings": {
    
    
    # 字段
    "properties": {
    
    
      # 姓名
      "name":{
    
    
        # 类型为text,表示此字段参与分词
        "type":"text",
        # 分词器为ik_smart
        "analyzer": "ik_smart"
      },
      # 年龄
      "age":{
    
    
        "type": "integer"
      },
      # 个人信息
      "info":{
    
    
        "type":"keyword"
      }
    }
  }
}

created successfully
insert image description here

find index library

Format: GET /index library name

GET /student

insert image description here

delete index library

Format: DELETE /index library name

DELETE /student

insert image description here

modify index library

Format: PUT /index library name/_mapping

Modifying the index library can only add fields, and cannot modify the original index library structure, such as adding a hobby field, the type is keyword, and does not participate in word segmentation;

PUT /student/_mapping
{
    
    
  "properties":{
    
    
    "hobby":{
    
    
      "type":"keyword"
    }
  }
}

insert image description here

Document Operations

add document

Format: POST /index library name/_doc/ID

Adding a document is equivalent to adding a piece of data, such as adding a document in the student index library;

POST /student/_doc/1
{
    
    
  "name":"zhangsan",
  "age":"35",
  "info":"中国人",
  "hobby":"reading"
}

insert image description here

find documentation

Format: GET /index library name/_doc/ID

GET /student/_doc/1

insert image description here

delete document

Format: DELETE /index library name/_doc/ID

DELETE /student/_doc/1

insert image description here

modify document

Format: PUT /index library name/_doc/ID or POST /index library name/_update/ID

# 方式一:全量修改,会删除旧文档,添加新文档
PUT /student/_doc/1
{
    
    
  "name":"lisi",
  "age":"60",
  "info":"中国人",
  "hobby":"walk"
}

# 方式二:增量修改,修改指定字段
POST /student/_update/1
{
    
    
  "doc":{
    
    
    "name":"wangwu"
  }
}

insert image description here

Summarize

Add, create, modify using POST, PUT, search using GET, delete using DELETE

Guess you like

Origin blog.csdn.net/qq_42108331/article/details/131882965