0
点赞
收藏
分享

微信扫一扫

elasticsearch的常用命令

金牛豆豆 2022-06-20 阅读 66

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"
}'

elasticsearch的常用命令_json

删除一个文档
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 条评论