一、查看集群健康:
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
发现索引占用的磁盘空间变多了,侧边说明它拥有了更多的数据。