Restful style and basic operation of index

Restful style and basic operation of index

One, Restful style

A software architecture style, not a standard, only provides a set of design principles and constraints. It is mainly used for software that interacts between client and server. Software designed based on this style can be more concise, more layered, and easier to implement mechanisms such as caching.

Basic Rest command description:

method url address description
PUT localhost:9200/index name/type name/document id Create document (specify document id)
POST localhost:9200/index name/type name Create document (random document id)
POST localhost:9200/index name/type name/document id/_update Modify the document
DELETE localhost:9200/index name/type name/document id Delete document
GET localhost:9200/index name/type name/document id Query documents by document id
POST localhost:9200/index name/type name/_search Query all data

Two, the basic operation on the index

Create an index

PUT /索引名/~类型名~/文档id
{ 
  请求体
}
# PUT 创建命令  test1 索引 type1 类型 1 id

PUT /latte/type1/1
{
  "name": "latteitcjz",
  "age": 20
  
}

# 返回结果
# 警告信息: 不支持在文档索引请求中的指定类型
# 而是使用无类型的断点(/{index}/_doc/{id}, /{index}/_doc, or /{index}/_create/{id}).
{
  "_index" : "latte",	# 索引
  "_type" : "type1",	# 类型(已经废弃)
  "_id" : "1",			# id
  "_version" : 1,		# 版本
  "result" : "created",	# 操作类型
  "_shards" : {			# 分片信息
    "total" : 2,
    "successful" : 1,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

Insert picture description here

The index has been added automatically! The data has also been successfully added, which is why I said that you can use it as a database for learning in the early stage!

Insert picture description here

So do you need to specify the type for the name field. After all, our relational database needs to specify the type!

  • String type
    text, keyword
  • Numerical types
    long, integer, short, byte, double, float, half_float, scaled_float
  • Date type
    date
  • Boolean value type
    boolean
  • Binary type
    binary
  • and many more…

Specify the type of field

Create rules
Insert picture description here

Get this rule! You can get specific information through a GET request!

Insert picture description here

View the default information

Insert picture description here

Insert picture description here

If your own document field is not specified, then es will give us the default configuration field type!

Expansion : Through the command elasticsearch index situation! A lot of current information of es can be obtained through GET _cat/!

Insert picture description here

Modify index

# 只会修改指定项,其他内容保证不变
POST /test3/_doc/1/_update
{
    
    
  "doc":{
    
    
    "name": "张山"
  }
}


# GET test3/_doc/1

{
    
    
  "_index" : "test3",
  "_type" : "_doc",
  "_id" : "1",
  "_version" : 2,
  "_seq_no" : 1,
  "_primary_term" : 1,
  "found" : true,
  "_source" : {
    
    
    "name" : "张山",
    "age" : 20,
    "birth" : "1999-06-10"
  }
}

I used to use PUT, if the field is incomplete (the field will be discarded if the field is written less), the original data will be overwritten!

Insert picture description here

Version plus 1

The current method uses POST, and _update is added after the corresponding request, which will only update the submitted fields!

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Delete index

Through the DELETE command to achieve deletion, according to your request to determine whether to delete the index or delete the document record!
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43803285/article/details/114780578