![](https://img.haomeiwen.com/i15999829/b5e59d7a94488e16.png)
7.0 之,type变为_doc
![](https://img.haomeiwen.com/i15999829/d011ed79353fea93.png)
create
![](https://img.haomeiwen.com/i15999829/d6fce22205d077c7.png)
![](https://img.haomeiwen.com/i15999829/7a87af65e27abe1c.png)
get
![](https://img.haomeiwen.com/i15999829/83f4aaa51ec085b1.png)
index 覆盖创建/更新
![](https://img.haomeiwen.com/i15999829/2437c070625ec99e.png)
Update
![](https://img.haomeiwen.com/i15999829/ebcb9903b0af314e.png)
bulk api
![](https://img.haomeiwen.com/i15999829/ab91c5f7e95abf3c.png)
![](https://img.haomeiwen.com/i15999829/3fbe845cd5836cb7.png)
![](https://img.haomeiwen.com/i15999829/23bc2446112f8a10.png)
mget
![](https://img.haomeiwen.com/i15999829/81f290d9ce7dc1d9.png)
![](https://img.haomeiwen.com/i15999829/e0a448181c44154a.png)
mget 是通过文档id获取数据
msearch
![](https://img.haomeiwen.com/i15999829/2785a7007a096894.png)
msearch 是根据查询条件,搜索到相应文档。
常见返回错误
![](https://img.haomeiwen.com/i15999829/070d8ecf70cc64f3.png)
批量操作,不要发送过多数据,否则也会导致性能的下降,一般多少数据才算是过多呢?
比较笼统的说,一般建议是1000-5000个文档,如果你的文档很大,可以适当减少队列,大小建议是5-15MB,默认不能超过100M。会报错
############Create Document############
#create document. 自动生成 _id
POST users/_doc
{
"user" : "Mike",
"post_date" : "2019-04-15T14:12:12",
"message" : "trying out Kibana"
}
#create document. 指定Id。如果id已经存在,报错
PUT users/_doc/1?op_type=create
{
"user" : "Jack",
"post_date" : "2019-05-15T14:12:12",
"message" : "trying out Elasticsearch"
}
#create document. 指定 ID 如果已经存在,就报错
PUT users/_create/1
{
"user" : "Jack",
"post_date" : "2019-05-15T14:12:12",
"message" : "trying out Elasticsearch"
}
### Get Document by ID
#Get the document by ID
GET users/_doc/1
### Index & Update
#Update 指定 ID (先删除,在写入)
GET users/_doc/1
PUT users/_doc/1
{
"user" : "Mike"
}
#GET users/_doc/1
#在原文档上增加字段
POST users/_update/1/
{
"doc":{
"post_date" : "2019-05-15T14:12:12",
"message" : "trying out Elasticsearch"
}
}
### Delete by Id
# 删除文档
DELETE users/_doc/1
### Bulk 操作
#执行两次,查看每次的结果
#执行第1次
POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test2", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }
#执行第2次
POST _bulk
{ "index" : { "_index" : "test", "_id" : "1" } }
{ "field1" : "value1" }
{ "delete" : { "_index" : "test", "_id" : "2" } }
{ "create" : { "_index" : "test2", "_id" : "3" } }
{ "field1" : "value3" }
{ "update" : {"_id" : "1", "_index" : "test"} }
{ "doc" : {"field2" : "value2"} }
### mget 操作
GET /_mget
{
"docs" : [
{
"_index" : "test",
"_id" : "1"
},
{
"_index" : "test",
"_id" : "2"
}
]
}
#URI中指定index
GET /test/_mget
{
"docs" : [
{
"_id" : "1"
},
{
"_id" : "2"
}
]
}
GET /_mget
{
"docs" : [
{
"_index" : "test",
"_id" : "1",
"_source" : false
},
{
"_index" : "test",
"_id" : "2",
"_source" : ["field3", "field4"]
},
{
"_index" : "test",
"_id" : "3",
"_source" : {
"include": ["user"],
"exclude": ["user.location"]
}
}
]
}
### msearch 操作
POST kibana_sample_data_ecommerce/_msearch
{}
{"query" : {"match_all" : {}},"size":1}
{"index" : "kibana_sample_data_flights"}
{"query" : {"match_all" : {}},"size":2}
### 清除测试数据
#清除数据
DELETE users
DELETE test
DELETE test2
Document API https://www.elastic.co/guide/en/elasticsearch/reference/7.1/docs.html
网友评论