1.elasticsearch 命令的基本格式
RESTful接口URL的格式:
http://localhost:9200/<index>/<type>/[<id>]
其中index、type是必須提供的。id是可選的,不提供es回自動生成。index、type將信息進行分層,利於管理。index可以理解為數據庫;type理解為數據表;id相當於數據表中記錄的主鍵,是唯一的。
2.elasticsearch基本的增刪改
1) 增加
例如:向store索引中增加一些書籍,如果沒有store這個索引,回自動創建
PUT地址:http://localhost:9200/store/books/1
Json內容:
{ "title": "Elasticsearch: The Definitive Guide", "name" : { "first" : "Zachary", "last" : "Tong" }, "publish_date":"2015-02-06", "price":"49.99" }
通過elasticsearch-head查詢結果:
2)刪除
DELETE地址:http://localhost:9200/hello/books/1
查詢結果:
3)更改
①可以通過覆蓋的方式更新
PUT地址:http://localhost:9200/store/books/1
JSON數據:
{ "title": "Elasticsearch: The Definitive Guide", "name" : { "first" : "Zachary", "last" : "Tong" }, "publish_date":"2016-02-06", "price":"99.99" }
② 通過_update API的方式單獨更新你想要更新的
POST地址:http://localhost:9200/store/books/2/_update
JSON內容:
{ "doc": { "price" : 88.88 } }
3.elasticsearch查詢
elasticSearch查詢分三種,一是瀏覽器查詢,二是curl查詢,三是請求體查詢GET或POS。
注:采用_search的模糊查詢(包括bool過濾查詢、 嵌套查詢、range范圍過濾查詢等等),url可以不必指定type,只用指定index查詢就行,具體例子看"2.1.4 elasticSearch查詢 ③query基本匹配查詢"節點的具體查詢實例
1)瀏覽器查詢
?pretty 返回格式化后的json,pretty參數表示返回結果格式美觀
3)GET查詢
GET地址:http://localhost:9200/store/books/2?pretty