Elasticsearch学习<二>Elasticsearch常用命令

elasticsearch支持restapi可以直接通过postman访问:

1、_cat:

urlmethodexplain
http://ip:port/_cat/nodesget查看节点信息
http://ip:port/_cat/healthget查看健康情况
http://ip:port/_cat/masterget查看主节点信息
http://ip:port/_cat/indicesget查看所有索引,类似于数据库的show databases;
   

 

2、如何保存一个文档(保存在哪个索引的哪个类型下,就类似于保存数据库的哪个库的哪张表下面)

urlmethoddistribute
http://ip:port/index/type/keyputindex是索引名,类似于数据库;type是类型名,类似于数据表;key是数据的唯一值;参数是json数据。多次请求就是更新操作
http://ip:port/index/type/keypost和put类似只不过是可以不带id保存,每次保存自动生成id。

3、如何查询一个文档

urlmethoddistribute
http://ip:port/index/type/keyget返回数据
模拟乐观锁  
http://ip:port/index/type/key?if_seq_no=2&if_primary_term=1put 

 

4、更新文档

urlmethoddistribute
http://ip:port/index/type/key/_updatepost会对比原数据,如果数据相同就不会再进行任何操作。参数:{"doc":{data}}必须是doc的对象
http://ip:port/index/type/key/post/put不会检查原数据,一直是更新操作,参数就是更新对象的json。

5、删除文档&索引

urlmethoddistribute
http://ip:port/index/type/key/delete删除文档
http://ip:port/indexdelete删除索引

 

6、bulk批量api

需要使用kibana操作:

urlmethoddistribute
/index/type/key/  POST 

参数格式:

{"index":{"_id":"1"}}
{"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"}

第一个json对象是操作类型,第二个json对象是新增数据

elasticsearch官方提供的操作数据:链接:https://pan.baidu.com/s/1VFH48rP3UhJfJemFEZNmcw   提取码:ibvj 


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值