elasticSearch基本使用
1.elasticSearch命令的基本格式
RESTful接口URL的格式:
http://localhost:9200/<index>/<type>/[<id>]
其中index、type是必须提供的。id是可选的,不提供es会自动生成。index、type将信息进行分层,利于管理。index可以理解为数据库;type理解为数据表;id相当于数据库表中记录的主键,是唯一的。
注:在url网址后面加"?pretty",会让返回结果以工整的方式展示出来,适用所有操作数据类的url。"?"表示引出条件,"pretty"是条件内容。
2.elasticSearch基本的增删改
1.1 增
curl -H "Content-Type: application/json" -XPUT 'http://192.168.2.232:9200/store/books/1?pretty' -d '{
"title": "Elasticsearch: The Definitive Guide",
"name" : {
"first" : "Zachary",
"last" : "Tong"
},
"publish_date":"2015-02-06",
"price":"49.99"
}'
1.2 删
curl -XDELETE 'http://192.168.2.232:9200/store/books/1?pretty'
1.3 更新
(1)可通过覆盖更新
curl -H "Content-Type:application/json" -XPUT 'http://192.168.2.232:9200/store/books/1?pretty' -d '{
"title": "Elasticsearch: The Definitive Guide", "name" : { "first" : "Zachary", "last" : "Tong" }, "publish_date":"2016-02-06", "price":"99.99"}'(2) 通过_update API的方式单独更新你想要更新的curl -H "Content-Type: application/json" -XPOST 'http://192.168.2.232:9200/store/books/1/_update?pretty' -d '{
"doc": { "price" : 88.88 }}'

浙公网安备 33010602011771号