Elasticsearch学习笔记之—index管理

GET /_cat/nodes?v
GET /_cat/health?v

 

1、索引建立

PUT /location?pretty

2、查看索引

GET /_cat/indices?v

3、删除索引命令

DELETE /location?pretty

4、部分字段索引更新

POST /ecommerce/product/1/_update
{
  "doc": {
    "name": "新值"
  }
} 

5、索引信息全部更新

PUT /ecommerce/product/1
{
  "id":2, 
  "name": "test yagao2444", 
  "desc": "youxiao fangzhu2555"
}

6、删除单条索引

DELETE /music/children/1

 

批量处理

1、根据文档id批量获得文档内容

第一种:

GET /_mget
{
 "docs":[
   {
     "_index":"music",
     "_type":"children",
     "_id":"1"
   },
   {
     "_index":"music",
     "_type":"children",
     "_id":"2"
   }
 ]
}

 第二种:

GET /music/children/_mget
{
    "ids": [1, 2]
}

第三种:

GET /music/children/_mget
{
   "docs" : [
      {
         "_id":1
      },
      {
         "_id":2
      }
   ]
}

2、批量新增

POST /_bulk
{ "index": { "_index": "ecommerce", "_type":"product"}}
{ "name": "test yagao", "desc": "youxiao fangzhu"}
{ "index": { "_index": "ecommerce", "_type":"product"}}
{ "name": "test yagao2", "desc": "youxiao fangzhu2"}
POST /_bulk
{"index": { "_index": "ecommerce", "_type":"product","_id":1}}
{"id":1, "name": "test yagao", "desc": "youxiao fangzhu"}
{"index": { "_index": "ecommerce", "_type":"product","_id":2}}
{"id":2, "name": "test yagao2", "desc": "youxiao fangzhu2"}

3、批量删除

POST /_bulk
{ "delete": { "_index": "ecommerce", "_type": "product", "_id": "1"}}
{ "delete": { "_index": "ecommerce", "_type": "product", "_id": "2"}}

4、批量更新

POST /_bulk
{ "update": { "_index": "ecommerce", "_type": "product", "_id": "1","retry_on_conflict" : 3 }}
{ "doc" : {"name" : "new_name1"} }
{ "update": { "_index": "ecommerce", "_type": "product", "_id": "2","retry_on_conflict" : 3 }}
{ "doc" : {"name" : "new_name2"} }

  每次update都会调用 InternalEngine 中的get方法,来获取整个文档信息,从而实现针对特定字段进行修改,这也就导致了每次更新要获取一遍原始文档,性能上会有很大影响。所以根据使用场景,有时候使用index会比update好很多。

5、index和create区别

  index不管存在不存在,都会执行成功,如果没有指定version,version会自增。

  create如果存在,就不创建了,如果不存在就创建。

posted @ 2019-12-20 11:42  星星c#  阅读(582)  评论(0编辑  收藏  举报