1 Introduction
Mainly introduce the basic API operation of index request, use postman to request, the prefix address of the interface request is unified as elasticsearch deployment IP address + port number (for example, http://192.168.51.4:9200. The following provides the interface address JSON export for postman test file:
Postman interface collection download address https://download.csdn.net/download/qq_15769939/15469409
2 Index basic operations
2.1 Cluster health status
Official website address:
https://www.elastic.co/guide/cn/elasticsearch/guide/current/_cluster_health.html#_cluster_health
Request method | interface address |
---|---|
GET | /_cluster/health |
{
"cluster_name": "auskat-elasticsearch",
"status": "yellow",
"timed_out": false,
"number_of_nodes": 1,
"number_of_data_nodes": 1,
"active_primary_shards": 8,
"active_shards": 8,
"relocating_shards": 0,
"initializing_shards": 0,
"unassigned_shards": 1,
"delayed_unassigned_shards": 0,
"number_of_pending_tasks": 0,
"number_of_in_flight_fetch": 0,
"task_max_waiting_in_queue_millis": 0,
"active_shards_percent_as_number": 88.88888888888889
}
In response to the most important information is in a status
field. The status can be one of the following three values:
-
green
All primary and replica shards have been allocated. Your cluster is 100% available.
-
yellow
All the primary shards have been sharded, but at least one copy is missing. No data will be lost, so the search results are still complete. However, your high availability is weakened to some extent. If more fragments disappear, you will lose the data. The
yellow
thought of as a warning of the need for timely investigation. -
red
At least one primary shard (and all its copies) are missing. This means that you are missing data: the search can only return part of the data, and the write request assigned to this shard will return an exception.
2.2 Create an index
Request method | interface address | Remarks |
---|---|---|
PUT | /index_api_demo | index_api_demo The name of the index to be created |
传递的JSON参数
{
"settings": {
"index": {
"number_of_shards": "2",
"number_of_replicas": "0"
}
}
}
- number_of_shards Number of shards
- number_of_replicas number of replicas
返回结果
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "index_api_demo"
}
2.3 Query specified index information
Request method | interface address | Remarks |
---|---|---|
GET | /index_api_demo | index_api_demo The name of the index to be queried |
请求结果
{
"index_api_demo": {
"aliases": {
},
"mappings": {
},
"settings": {
"index": {
"creation_date": "1614258485568",
"number_of_shards": "2",
"number_of_replicas": "0",
"uuid": "vnErVtHjSH-n29F1df8tDg",
"version": {
"created": "7040299"
},
"provided_name": "index_api_demo"
}
}
}
}
2.4 Query the information of all indexes
Request method | interface address |
---|---|
GET | /_cat/indices?v |
请求结果
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open index_mapping ECD_xsBERPa5gSLCYe3r4g 1 1 0 0 283b 283b
green open index_demo NieZpAnYTSSSkC1umY7u7g 5 0 0 0 1.3kb 1.3kb
green open my_doc ZEEYJASoTIqKyr8SycMQxw 1 0 5 3 11.4kb 11.4kb
green open index_field xRd8d_bvSmWYK9_HFJfe2A 1 0 0 0 283b 283b
green open index_api_demo vnErVtHjSH-n29F1df8tDg 2 0 0 0 566b 566b
2.5 Delete index
Request method | interface address | Remarks |
---|---|---|
DELETE | /index_api_demo | index_api_demo The name of the index to be queried |
请求结果
{
"acknowledged": true
}
2.6 Create mappings while creating an index
Request method | interface address | Remarks |
---|---|---|
PUT | /index_mapping_demo | index_mapping_demo The name of the index to be created |
传递json数据
{
"mappings": {
"properties": {
"realname": {
"type": "text",
"index": true
},
"username": {
"type": "keyword",
"index": false
}
}
}
}
index: The default is true, if set to false, then this field will not be indexed
Official address: https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index.html
index
The
index
option controls whether field values are indexed. It acceptstrue
orfalse
and defaults totrue
. Fields that are not indexed are not queryable.
请求结果
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "index_mapping_demo"
}
2.7 Modify mappings
Request method | interface address | Remarks |
---|---|---|
POST | /index_mapping_demo/_mapping | index_mapping_demo index name |
传递JSON数据
{
"properties": {
"id": {
"type": "long"
},
"age": {
"type": "integer"
},
"money1": {
"type": "double"
},
"money2": {
"type": "float"
},
"sex": {
"type": "byte"
},
"score": {
"type": "short"
},
"is_teenger": {
"type": "boolean"
},
"birthday": {
"type": "date"
},
"relationship": {
"type": "object"
}
}
}
请求结果
{
"acknowledged": true
}
Once an attribute is created, it cannot be modified, but additional attributes can be added
3 Related information
- The blog post is not easy, everyone who has worked so hard to pay attention and praise, thank you