關於curl的介紹,請移步
Elasticsearch學習概念之curl
啟動es,請移步
Elasticsearch的前后台運行與停止(tar包方式)
Elasticsearch的前后台運行與停止(rpm包方式)
創建索引庫,我這里命名為zhouls
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT 'http://192.168.80.200:9200/zhouls'
{"acknowledged":true}[hadoop@djt002 elasticsearch-2.4.3]$
這里,是跟之前的elasticsearch.yml修改對應起來的。
我們可以驗證下,輸入localhost或者127.0.0.1都會出現無法連接,不信你嘗試。
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT 'http://192.168.80.200:9200/zhouls'
{"acknowledged":true}[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT 'http://localhost:9200/zhouls'
curl: (7) couldn't connect to host
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT 'http://127.0.0.1:9200/zhouls'
curl: (7) couldn't connect to host
[hadoop@djt002 elasticsearch-2.4.3]$
為了方便,更改為0.0.0.0
然后,重啟es
[hadoop@djt002 elasticsearch-2.4.3]$ jps
2811 Jps
2741 Elasticsearch
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT 'http://localhost:9200/zhouls'
{"error":{"root_cause":[{"type":"index_already_exists_exception","reason":"already exists","index":"zhouls"}],"type":"index_already_exists_exception","reason":"already exists","index":"zhouls"},"status":400}[hadoop@djt002 elasticurl -XPUT 'http://127.0.0.1:9200/zhouls'
{"error":{"root_cause":[{"type":"index_already_exists_exception","reason":"already exists","index":"zhouls"}],"type":"index_already_exists_exception","reason":"already exists","index":"zhouls"},"status":400}[hadoop@djt002 elasticurl -XPUT 'http://192.168.80.200:9200/zhouls'
{"error":{"root_cause":[{"type":"index_already_exists_exception","reason":"already exists","index":"zhouls"}],"type":"index_already_exists_exception","reason":"already exists","index":"zhouls"},"status":400}[hadoop@djt002 elasticsearch-2.4.3]$
報這個錯誤,是正常的,因為,你重復創建索引庫。根據經驗之談,一般用內網ip。如我的192.168.80.200。建議指定內網ip
本地回環地址:127.0.0.1
內網地址:192.168.80.200
外網地址:10.29.0.2
在這里0.0.0.0 表示可以通過上面所有ip都可以訪問
以上是,Elasticsearch之curl創建索引庫的方式1,以下是,Elasticsearch之curl創建索引庫的方式2
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT 'http://192.168.80.200:9200/zhouls'
{"error":{"root_cause":[{"type":"index_already_exists_exception","reason":"already exists","index":"zhouls"}],"type":"index_already_exists_exception","reason":"already exists","index":"zhouls"},"status":400}[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPOST 'http://192.168.80.200:9200/zhouls1'
{"acknowledged":true}[hadoop@djt002 elasticsearch-2.4.3]$
測試完,及時刪除。
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT 'http://192.168.80.200:9200/zhouls'
{"error":{"root_cause":[{"type":"index_already_exists_exception","reason":"already exists","index":"zhouls"}],"type":"index_already_exists_exception","reason":"already exists","index":"zhouls"},"status":400}[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPOST 'http://192.168.80.200:9200/zhouls1'
{"acknowledged":true}[hadoop@djt002 elasticsearch-2.4.3]$ curl -XDELETE 'http://192.168.80.200:9200/zhouls1'
{"acknowledged":true}[hadoop@djt002 elasticsearch-2.4.3]$