您的位置:首页 > 其它

008-elasticsearch【二】Url方式索引CRUD、文档操作、批量操作

2018-03-05 10:49 621 查看
一、Url索引操作

常用查看

查看集群健康:http://127.0.0.1:9200/_cat/health?v

查看集群节点:http://127.0.0.1:9200/_cat/nodes?v

查看索引信息:http://127.0.0.1:9200/_cat/indices?v

1.1、创建

PUT /customer?pretty
GET /_cat/indices?v




此时创建所以成功

1.2、插入文档

PUT /customer/external/1?pretty
{
"name": "John Doe"
}




1.3、查询文档

GET /customer/external/1?pretty




1.4、删除索引

DELETE /customer?pretty
GET /_cat/indices?v




二、文档操作

2.1、修改文档

执行添加

PUT /customer/external/1?pretty
{
"name": "John Doe"
}


在此执行以下,id一样,但是name值由John Doe变为Job Doe

PUT /customer/external/1?pretty
{
"name": "Jab Doe"
}




此时执行id为2 内容不变

PUT /customer/external/2?pretty
{
"name": "Jab Doe"
}


结果是新增的



  索引时,ID部分是可选的。如果未指定,Elasticsearch将生成一个随机ID,然后用它来索引文档。作为索引API调用的一部分,将返回实际的ID Elasticsearch生成(或我们在前面的示例中明确指定的内容)。

不加id执行,每次都是新增的

POST /customer/external?pretty
{
"name": "Jane Doe"
}




2.2、删除文档

DELETE /customer/external/2?pretty




三、批量操作

POST /customer/external/_bulk?pretty
{"index":{"_id":"1"}}
{"name": "John Doe" }
{"index":{"_id":"2"}}
{"name": "Jane Doe" }


以及更新删除

POST /customer/external/_bulk?pretty
{"update":{"_id":"1"}}
{"doc": { "name": "John Doe becomes Jane Doe" } }
{"delete":{"_id":"2"}}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: