elasticsearch交互式命令查询(三)
elasticsearch交互方式
1.elasticsearch交互方式
curl命令:
最繁琐
最复杂
最容易出错
不需要安装任何软件,值需要有curl命令
es-head插件
查看数据方便
操作相对容易
需要node环境
kibana
查看数据以及报表格式丰富
操作很简单
需要java环境和安装配置kibana
1.1.查看es基本信息
[root@elastic ~]# curl 192.168.81.210:9200/_cat
=^.^=
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_cat/tasks
/_cat/indices
/_cat/indices/{index}
/_cat/segments
/_cat/segments/{index}
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
1.2.查看es分片信息
下面的输出可以看出是分了5个片,一个主分片一个副本分片
[root@elastic ~]# curl 192.168.81.210:9200/_cat/shards
testinfo 2 p STARTED 0 261b 192.168.81.240 node-1
testinfo 2 r UNASSIGNED
testinfo 1 p STARTED 0 261b 192.168.81.240 node-1
testinfo 1 r UNASSIGNED
testinfo 3 p STARTED 0 261b 192.168.81.240 node-1
testinfo 3 r UNASSIGNED
testinfo 4 p STARTED 0 261b 192.168.81.240 node-1
testinfo 4 r UNASSIGNED
testinfo 0 p STARTED 0 261b 192.168.81.240 node-1
testinfo 0 r UNASSIGNED
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
1.3.使用curl命令创建索引
开启127.0.0.1访问地址
[root@elastic ~]# vim /etc/elasticsearch/elasticsearch.yml
network.host: 192.168.81.240,127.0.0.1
[root@elastic ~]# systemctl restart elasticsearch注意创建索引时,curl命令的参数一定要保持顺序
命令格式:curl -XPUT ‘es地址:prot/索引名?pretty’
1.创建索引
[root@elastic ~]# curl -XPUT '192.168.81.210:9200/testinfo?pretty'
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "testinfo"
}
2.查看索引
[root@elastic ~]# curl 192.168.81.210:9200/_cat/indices
yellow open testinfo iucttBn4SsWpFQA24V8pYg 5 1 0 0 1.2kb 1.2kb
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
1.4.使用curl向索引插入数据
命令格式:
curl -XPUT ‘es地址:port/索引/类型/id?pretty’ -H ‘COntent-Type: application/json’ -d’{值}’
[root@elastic ~]# curl -XPUT '192.168.81.210:9200/testinfo/user/1?pretty' -H 'COntent-Type: application/json' -d'
{
"first_name" : "jiang",
"last_name" : "xiaolong",
"age" : 99,
"about" : "I like linux", "interests": [ "sports", "music" ]
}
'
{
"_index" : "testinfo",
"_type" : "user",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1
}
在创建一个id为2的文本
[root@elastic ~]# curl -XPUT '192.168.81.210:9200/testinfo/user/2?pretty' -H 'COntent-Type: application/json' -d'
{
"first_name" : "jiang",
"last_name" : "xl",
"age" : 77,
"about" : "I like linux", "interests": [ "sports", "music" ]
}'
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
刚刚创建的两个数据都是指定id的我们来写一个不指定id的
格式:
curl -XPOST ‘es地址:port/索引/类型?pretty/’ -H ‘COntent-Type: application/json’ -d’{值}’
或
curl -XPOST ‘es地址:port/索引/类型/’ -H ‘COntent-Type: application/json’ -d’{值}’
这个输出是一行不如第一种
[root@elaticsearch ~]# curl -X POST '192.168.81.210:9200/testinfo/user?pretty' -H 'COntent-Type: application/json' -d'
{
"first_name" : "jiang",
"last_name" : "xl",
"age" : 77,
"about" : "I like linux", "interests": [ "sports", "music" ]
}'
{
"_index" : "testinfo",
"_type" : "user",
"_id" : "p-58inYBlNQwpkFxBxiY", #随机生成的
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1
}
再创建一个
[root@elastic ~]# curl -XPOST '192.168.81.210:9200/testinfo/user?pretty' -H 'COntent-Type: application/json' -d'
{
"first_name" : "zhang",
"last_name" : "jia",
"age" : 77,
"about" : "I like linux", "interests": [ "sports", "music" ]
}'
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
文章来源: jiangxl.blog.csdn.net,作者:Jiangxl~,版权归原作者所有,如需转载,请联系作者。
原文链接:jiangxl.blog.csdn.net/article/details/117018040
- 点赞
- 收藏
- 关注作者
评论(0)