elasticsearch:添加文档(二)

一、查看集群健康:
https://www.elastic.co/guide/en/elasticsearch/reference/6.3/getting-started-cluster-health.html
curl -X GET “localhost:9200/_cat/health?v”

epoch      timestamp cluster       status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1560743857 11:57:37  elasticsearch green           1         1      0   0    0    0        0             0                  -                100.0%

二、查看所有索引
https://www.elastic.co/guide/en/elasticsearch/reference/6.3/getting-started-list-indices.html
curl -X GET “localhost:9200/_cat/indices?v”
什么都没有返回,表明当前集群中还没有索引
三、添加文档
1、添加一条索引为info,类型为student,id为1的文档
https://www.elastic.co/guide/en/elasticsearch/reference/6.3/getting-started-query-document.html
curl -X PUT “localhost:9200/info/student/1?pretty” -H ‘Content-Type: application/json’ -d’
{
“name”: “hassan”,
“age”: “24”,
“hobby”: “basketball”
}

此时查看所有索引:

health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   info  wzzOhf_zQqu5ImV64O4npA   5   1          1            0      5.6kb          5.6kb

2、批量添加三个文档
https://www.elastic.co/guide/en/elasticsearch/reference/6.3/docs-bulk.html
curl -X POST “localhost:9200/_bulk” -H ‘Content-Type: application/json’ -d’
{ “create” : { “_index” : “info”, “_type” : “student”, “_id” : “2” } }
{ “name”: “harold”, “age”: “24”,“hobby”: “hiking”}
{ “create” : { “_index” : “info”, “_type” : “student”, “_id” : “3” } }
{ “name”: “Draymond”}
{ “create” : { “_index” : “info”, “_type” : “student”, “_id” : “4” } }
{ “name”: “Curry”, {“age”: “32”, “hobby”: “basketball”}

执行之后提示_id为4的文档创建失败,的确,{ “name”: “Curry”, {“age”: “32”, “hobby”: “basketball”}写错了,应该为{ “name”: “Curry”, “age”: “32”, “hobby”: “basketball”},多了一个大括号,查询info索引中的所有数据,发现id为2、3的都插入成功了,也就是说插入失败的数据不影响插入其它正确的数据,为了更好的验证这句话,再次批量插入两个文档,与上一次不同的是,第一个文档是错误的文档,第二个是正确的,以此来证明,错误的文档是否会阻断正确的文档:
curl -X POST “localhost:9200/_bulk” -H ‘Content-Type: application/json’ -d’
{ “create” : { “_index” : “info”, “_type” : “student”, “_id” : “5” } }
{ “name”: “Curry”, {“age”: “32”, “hobby”: “basketball”}
{ “create” : { “_index” : “info”, “_type” : “student”, “_id” : “6” } }
{ “name”: “Chris Paul”}

发现id为5的插入失败,6插入成功,这说明了文档与文档之间的操作是独立的,互不影响,
此时查看所有索引:

health status index uuid                   pri rep docs.count docs.deleted store.size pri.store.size
yellow open   info  wzzOhf_zQqu5ImV64O4npA   5   1          5            0     18.8kb         18.8kb

发现索引占用的磁盘空间变多了,侧边说明它拥有了更多的数据。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值