ElasticSearch2:操作数据CRUD

1.在上一篇中,我们已经讲解如何部署ElasticSearch服务和Kibana。

在这篇中,我们开始操作ElasticSearch,访问localhost:5601


2.命令

1)GET _cluster/health   访问cluster的健康状态以及基本情况

{
  "cluster_name": "elasticsearch",
  "status": "yellow",
  "timed_out": false,
  "number_of_nodes": 1,
  "number_of_data_nodes": 1,
  "active_primary_shards": 5,
  "active_shards": 5,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 5,
  "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": 50
}



2)GET _cat/health?v    访问集群健康状态以及基本情况

epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1514181596 13:59:56  elasticsearch yellow          1         1      5   5    0    0        5             0                  -                 50.0%

3)GET _cat/indices?v   获取ElasticSearch中的索引

health status index     uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   ecommerce BvZ4i7rHSUSqXeNpnS0KGg   5   1          3            0     17.4kb         17.4kb


4)PUT /test_index?pretty     手动添加索引

{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "test_index"
}

查看所有的索引

health status index      uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   ecommerce  BvZ4i7rHSUSqXeNpnS0KGg   5   1          3            0     17.4kb         17.4kb
yellow open   test_index QyN2wTh1RhmKgxAFWqz1cA   5   1          0            0      1.1kb          1.1kb

5)添加Document数据

格式 PUT /Index/Type/Document

{

   "xxxx":"value"

}

PUT /ecommerce/product/1
{
  "name":"gaolujie yao",
  "desc":"gaoxiao meibai",
  "price":30,
  "producer":"gaolujie producer",
  "tags":["fangzhu","meibai"]
}
PUT /ecommerce/product/2
{
  "name":"jiajieshi yao",
  "desc":"youxiao fangzhu",
  "price":25,
  "producer":"jiajieshi producer",
  "tags":["fangzhu"]
}
PUT /ecommerce/product/3
{
  "name":"zhonghua yao",
  "desc":"caoben zhiwu",
  "price":40,
  "producer":"zhonghua producer",
  "tags":["qingxing"]
}



6)查询Document数据 

格式:GET /Index/Type/Document

GET /ecommerce/product/1
GET /ecommerce/product/2
GET /ecommerce/product/3


7)删除Document数据

DELETE /ecommerce/product/1


8)修改Document数据

覆盖修改:

PUT /ecommerce/product/1
{
  "name":"jiaqiangban gaolujie yao",
  "desc":"gaoxiao meibai",
  "price":30,
  "producer":"gaolujie producer",
  "tags":["fangzhu","meibai","jiaqiang"]
}


选择性修改:

POST /ecommerce/product/1
{
  "name":"gaolujie yagao",
  "tags":["fangzhu","meibai"]
}
POST /ecommerce/product/1/_update
{
  "doc":{
    "name":"gaolujie yagao beta1",
    "tags":["fangzhu","meibai","beta1"]
  }
}



3.简单的ElasticSearch操作就结束了









你可能感兴趣的:(ElasticSearch)