ElasticSearch Rest style operation (1) index operation

ElasticSearch Rest style operation (1) index operation

Basic Rest command description

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

1. Create an index

PUT /test1/type1/1
{
  "name":"洪七公",
  "age":3
}

Insert picture description here
Insert picture description here

2. Specify the type of field

Common field types

String type text, keyword
numeric type long, integer, short, byte, double, float, half float, scalet float
date type date
Boolean type boolean
binary type binary
etc...

Example: execute the following script

PUT /test2
{
  "mappings": {
    "properties": {
      "name":{
        "type": "text"
      },
      "age":{
        "type": "long"
      },
      "birthday":{
        "type": "date"
      }
    }
  }
}

Insert picture description here
View Results:
Insert picture description here

3. GET command

GET test2

Insert picture description here

4. Get health value

GET _cat/health

Insert picture description here

5. Get version information

GET _cat/indices?v

Insert picture description here

6. Modify

6.1. Modification method 1

POST /test1/type1/1
{
  "name":"张三丰",
  "age":33
}

Execution:
Insert picture description here
Query:
Insert picture description here

6.2. Modification 2

POST /test1/type1/1/_update
{
  "doc":{
    "name":"六小龄童"
  }
}

Insert picture description here

7, delete

DELETE test2

Insert picture description here
Special thanks: Mad God said Java

Guess you like

Origin blog.csdn.net/Asia1752/article/details/111317449