Elasticsearch之curl创建索引库和索引时注意事项
Posted 大数据和人工智能躺过的坑
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Elasticsearch之curl创建索引库和索引时注意事项相关的知识,希望对你有一定的参考价值。
前提,
Elasticsearch之curl创建索引库
Elasticsearch之curl创建索引
注意事项
1、索引库名称必须要全部小写,不能以下划线开头,也不能包含逗号
2、如果没有明确指定索引数据的ID,那么es会自动生成一个随机的ID,需要使用POST参数
curl -XPOST http://192.168.80.200:9200/zhouls/emp/ -d \'{"name" : "tom"}\'
3、如果想要确定我们创建的都是全新的数据
1:使用随机ID(post方式)
2:在url后面添加参数
curl -XPUT http://192.168.80.200:9200/zhouls/emp/2/_create -d \'{"name":"tom","age":25}\'
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT \'http://192.168.80.200:9200/zhouls/emp/1\' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}[hadoop@djt002 elasticsearch-2.4.3]$ ^C
[hadoop@djt002 elasticsearch-2.4.3]$ ^C
[hadoop@djt002 elasticsearch-2.4.3]$ ^C
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT \'http://192.168.80.200:9200/zhouls/emp/1\' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"1","_version":2,"_shards":{"total":2,"successful":1,"failed":0},"created":false}[hadoop@djt002 elasticsearch-2.4.3]$ ^C
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPOST \'http://192.168.80.200:9200/zhouls/emp/1\' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"1","_version":3,"_shards":{"total":2,"successful":1,"failed":0},"created":false}[hadoop@djt002 elasticsearch-2.4.3]$ ^C
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT \'http://192.168.80.200:9200/zhouls/emp\' -d\'{"name":"tom","age":25}\'
No handler found for uri [/zhouls/emp] and method [PUT][hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPOST \'http://192.168.80.200:9200/zhouls/emp\' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"AVpdAus-cJQ8qYq5I_Er","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPOST \'http://192.168.80.200:9200/zhouls/emp\' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"AVpdBaixcJQ8qYq5I_Es","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
得出,
不指定id,就必须得用-XPOST
3、
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT \'http://192.168.80.200:9200/zhouls/emp/1\' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}[hadoop@djt002 elasticsearch-2.4.3]$ ^C
[hadoop@djt002 elasticsearch-2.4.3]$ ^C
[hadoop@djt002 elasticsearch-2.4.3]$ ^C
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT \'http://192.168.80.200:9200/zhouls/emp/1\' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"1","_version":2,"_shards":{"total":2,"successful":1,"failed":0},"created":false}[hadoop@djt002 elasticsearch-2.4.3]$ ^C
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPOST \'http://192.168.80.200:9200/zhouls/emp/1\' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"1","_version":3,"_shards":{"total":2,"successful":1,"failed":0},"created":false}[hadoop@djt002 elasticsearch-2.4.3]$ ^C
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT \'http://192.168.80.200:9200/zhouls/emp\' -d\'{"name":"tom","age":25}\'
No handler found for uri [/zhouls/emp] and method [PUT][hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPOST \'http://192.168.80.200:9200/zhouls/emp\' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"AVpdAus-cJQ8qYq5I_Er","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPOST \'http://192.168.80.200:9200/zhouls/emp\' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"AVpdBaixcJQ8qYq5I_Es","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT \'http://192.168.80.200:9200/zhouls/emp/2/._create -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"2_create","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true}[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$ curl -XPUT \'http://192.168.80.200:9200/zhouls/emp/2_create \' -d\'{"name":"tom","age":25}\'
{"_index":"zhouls","_type":"emp","_id":"2_create","_version":2,"_shards":{"total":2,"successful":1,"failed":0},"created":false}[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
[hadoop@djt002 elasticsearch-2.4.3]$
这样做的好处,是,只要这条命令成功,那么就一定是新增的。
以上是关于Elasticsearch之curl创建索引库和索引时注意事项的主要内容,如果未能解决你的问题,请参考以下文章