该篇文章的操作均在kibana中的Dev Tools
查看es中的所有索引
GET /_cat/indices?v
或使用linux 中执行curl命令
curl -GET IP:9200/_cat/indices?v
返回
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
说明我们的es中还没有任何所有
创建索引
使用PUT命令,创建名称为customer的索引
PUT /customer?pretty
返回
{ "acknowledged": true, "shards_acknowledged": true, "index": "customer" }
创建Document,当索引创建完成后,我们就可以向索引插入数据了
插入一条ID为1的document
PUT /customer/_doc/1?pretty { "name": "zhangSan" }
返回
{ "_index": "customer", "_type": "_doc", "_id": "1", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "_seq_no": 0, "_primary_term": 1 }
查询Document
查询我们刚刚创建的zhangSan,这里我们按照ID查询
GET /customer/_doc/1?pretty
返回
{ "_index": "customer", "_type": "_doc", "_id": "1", "_version": 1, "found": true, "_source": { "name": "zhangSan" } }
查询该索引下的所有文档
GET /customer/_search?q=*
替换Document
把我们刚刚创建的zhangSan替换为liSi
PUT /customer/_doc/1?pretty { "name": "liSi" }
返回
{ "_index": "customer", "_type": "_doc", "_id": "1", "_version": 2, "result": "updated", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "_seq_no": 1, "_primary_term": 1 }
与替换有相同功能的我们还可以更新
POST /customer/_doc/1/_update?pretty { "doc": { "name": "liSi" } }
tip:es在更新或替换新纪录,实际上是先删除,再新增
删除Document
删除ID为1的记录
DELETE /customer/_doc/1?pretty
返回
{ "_index": "customer", "_type": "_doc", "_id": "1", "_version": 3, "result": "deleted", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "_seq_no": 2, "_primary_term": 1 }
删除索引
DELETE /customer?pretty
返回
{ "acknowledged": true }