Adding, deleting, modifying and querying API in elastic search mode

Adding, deleting, modifying and querying API in elastic search mode

1. Initialize index

----—–

Initialize index
You can initialize the index before creating it
For example, specify the number of shards and replicas

PUT http://ip:9200/library/
{
"settings":{
    "index":{
            "number_of_shards":5,
            "number_of_replicas":1
        }
    }
}

The number of replicas above can also be replaced by:
Blocks.read'only: set to true. The current index can only be read, not written or updated
blocks.read: set to true to disable read operation
blocks.write: set to true to disable writing
blocks.metadata: set to true to disable metadata operations

----—-

#The detailed configuration information of the index can be obtained through GET with the parameter ﹐ settings
GET /library/_settings

#Get the information of two indexes at the same time
GET /library,library/_settings

#Get information for all indexes
GET /_all/_settings

----—-

2. Create an index: add, delete, modify and query

Create an index
----Index name
        |  Type Name
        |    |    File ID
        |    |      |
        ☟    ☟      ☟ 
PUT /library/books/1
{
    "title": "Elasticsearch:  The Definitive Guide",
    "name":{
                "first":"Zachary",
                "last":"Tong"
    },
    "publish_date":"2017-12-27",
    "price":"99.99"
}

ID You can also choose not to set. If not, a uuid
POST /library/books/
{
 "title":"Elasticsearch Blueprints",
 "name":{
         "first":"Vineeth",
         "last":"Mohan"
    }
 "publish_date":"2017-12-27",
 "price":"98.99"
}

#Get document information through ID
GET /library/books/1
GET /library/books/2
GET uuid


#Get the specified field through
GET /library/books/1?_source=title
GET /library/books/1?_source=title,price
GET /library/books/1?_source

#We can update the documents under the same ID by overwriting
PUT /library/books/1
{
    "title": "Elasticsearch:  The Definitive Guide",
    "name":{
                "first":"Zachary",
                "last":"Tong"
    },
    "publish_date":"2017-12-27",
    "price":"88.88"
}

GET /library/books/1

#You can update the fields you want to update individually through the update API
POST /library/books/1/_update
{
    "doc":{
        "price":10
    }
}

GET /library/books/1


#How to delete a document
DELETE /library/books/1
DELETE /library/books
DELETE /library
GET /library

Extension: built in fields and types of Elasticsearch

Built in fields:
_uid, _id, _type, _source, _all, _analyzer , _boost , _parent, _routing, _index, _size, _timestamp, _ttl

Field type:
String,Integer/long, Float/double, Boolean, Null, Date

Keywords: ElasticSearch

Added by kender on Tue, 05 May 2020 19:51:33 +0300