elasticsearch的常用命令

elasticsearch增加:
RESTful接口URL的格式:http://192.168.33.134:9200///[]
其中index、type是必须提供的。id是可选的,不提供es会自动生成。index、type将信息进行分层,利于管理。index可以理解为数据库;type理解为数据表;id相当于数据库表中记录的主键,是唯一的。

注:在url网址后面加"?pretty",会让返回结果以工整的方式展示出来,适用所有操作数据类的url。"?"表示引出条件,"pretty"是条件内容。
注:curl是linux下的http请求,-H "Content-Type: application/json"需要添加,否则会报错{“error”:“Content-Type header [application/x-www-form-urlencoded] is not supported”,“status”:406}

加"pretty"

  curl -H "Content-Type: application/json" -XPUT 'http://192.168.33.134:9200/store/books/1?pretty' -d '{
      "title": "Elasticsearch: The Definitive Guide",
      "name" : {
        "first" : "Zachary",
        "last" : "Tong"
      },
      "publish_date":"2015-02-06",
      "price":"49.99"
    }'

在这里插入图片描述

删除一个文档
curl -XDELETE ‘http://192.168.33.134:9200/store/books/1?pretty

可以通过覆盖的方式更新

curl -H "Content-Type:application/json" -XPUT 'http://192.168.33.134:9200/store/books/1?pretty' -d '{
  "title": "Elasticsearch: The Definitive Guide",
  "name" : {
    "first" : "Zachary",
    "last" : "Tong"
  },
  "publish_date":"2016-02-06",
  "price":"99.99"
}'

通过_update API的方式单独更新你想要更新的

curl -H "Content-Type: application/json" -XPOST 'http://192.168.33.134:9200/store/books/1/_update?pretty' -d '{
  "doc": {
     "price" : 88.88
  }
}'

通过浏览器IP+网址查询
http://192.168.33.134:9200/store/books/1?pretty

在linux通过curl的方式查询 通过ID获得文档信息
curl -XGET ‘http://192.168.33.134:9200/store/books/1?pretty

通过_source获取指定的字段
curl -XGET ‘http://192.168.33.134:9200/store/books/1?_source=title&pretty
curl -XGET ‘http://192.168.33.134:9200/store/books/1?_source=title,price&pretty
curl -XGET ‘http://192.168.33.134:9200/store/books/1?_source&pretty

推荐

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值