您的位置:首页 > 其它

Elasticsearch之curl创建索引库

2017-02-20 17:35 281 查看
  关于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

服务器一般都会有多种ip地址,
本地回环地址:127.0.0.1
内网地址:192.168.80.200
外网地址:10.29.0.2
在这里0.0.0.0 表示可以通过上面所有ip都可以访问

  以上是,Elasticsearch之curl创建索引库的方式1,以下是,Elasticsearch之curl[b]创建索引库的方式2[/b]



[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]$
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: