搭建好ES之后,想用命令行簡(jiǎn)單測(cè)試一下,涉及到了下面幾個(gè)命令,也遇到了一些問題,記錄一下。
首先創(chuàng)建兩個(gè)索引:
curl -X PUT "IP:9200/test_index"
curl -X PUT "IP:9200/test_index_1"
然后查看索引的簡(jiǎn)略信息
curl -X GET "IP:9200/_cat/indices"

查看索引簡(jiǎn)略信息.png
然后添加document數(shù)據(jù)
curl -H "Content-Type:application/json" -X POST "http://IP:9200/test_index/1?pretty" -d '{"name":"Shenzhen","area":["a1","a2"]}'
添加成功后會(huì)返回結(jié)果

添加document.png
最后查看dcument數(shù)量,如果IP后不加索引名稱,默認(rèn)統(tǒng)計(jì)所有索引中的總數(shù)據(jù)量
curl -X GET "IP:9200/_count"
curl -X GET "IP:9200/test_index/_count"

document計(jì)數(shù).png
在添加document數(shù)據(jù)的時(shí)候可能會(huì)發(fā)生錯(cuò)誤,當(dāng)使用PUT方法時(shí)報(bào)錯(cuò),當(dāng)使用POST方法且路徑后沒有添加“1”作為document的id的時(shí)候也會(huì)報(bào)錯(cuò),顯示結(jié)果如下。

添加document錯(cuò)誤信息.png
2023,繼續(xù)加油啦!