日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Elasticsearch 2.20入门篇:基本操作

發(fā)布時間:2025/7/14 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Elasticsearch 2.20入门篇:基本操作 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

????前面我們已經(jīng)安裝了Elasticsearch ,下一步我們要對Elasticsearch進行一些基本的操作。基本的操作主要有,建索引庫,插入數(shù)據(jù),查詢數(shù)據(jù),修改數(shù)據(jù),刪除數(shù)據(jù),刪除索引庫。

????備注:如果沒有特殊說明,本文章及后面所有的文章都在2.20版本中進行驗證,其他版本不能確定是否可用。

????由于官方文檔都是使用curl來進行實例操作,不太直觀,我更喜歡用圖形化界面來進行驗證。在本文及以后的例子中,我都是已RESTClient3.5來作為操作的工具。下載地址為http://code.fosshub.com/WizToolsorg-RESTClient/downloads,下載的文件是restclient-ui-3.5-jar-with-dependencies.jar。

程序運行: java -jar restclient-ui-3.5-jar-with-dependencies.jar

建索引庫

執(zhí)行PUT localhost:9200/customer?pretty

返回表示建庫成功:

{"acknowledged"?:?true }

說明:http方法PUT,url為localhost:9200/customer?pretty

查詢庫

執(zhí)行GET http://localhost:9200/_cat/indices?v

返回:

health status ? index ? ? ?pri ?rep ? ? ? docs.count docs.deleted store.size pri.store.size?

yellow open ? customer ? 5 ? 1 ? ? ? ? ?0 ? ? ? ? ? ? ? ? 0 ? ? ? ? ? ? ? ? ? 795b ? ? ? ?795b?

表示已經(jīng)建成了一個索引customer,主分片是5個,健康度是黃色,狀態(tài)是活動,文檔數(shù)為0。

插入數(shù)據(jù)

執(zhí)行?PUT localhost:9200/customer/external/1?pretty

參數(shù):{ ?"name": "John Doe" }

注意:Method選擇PUT,Body要設(shè)置成application/x-www-form-urlencoded; charset=UTF-8

返回值為:

{"_index"?:?"customer","_type"?:?"external","_id"?:?"1","_version"?:?1,"_shards"?:?{"total"?:?2,"successful"?:?1,"failed"?:?0},"created"?:?true }

界面如下:

我們再次執(zhí)行庫查詢,發(fā)現(xiàn)文檔數(shù)是1:GET http://localhost:9200/_cat/indices?v ?

health status ?index ? ? ?pri rep ? ? ? ?docs.count docs.deleted store.size pri.store.size?

yellow open ? customer ? 5 ? 1 ? ? ? ? ?1 ? ? ? ? ? ?0 ? ? ?3.5kb ? ? ? ? ?3.5kb?

查詢數(shù)據(jù)

執(zhí)行:GET?http://localhost:9200/customer/external/1?pretty

返回:

{"_index"?:?"customer","_type"?:?"external","_id"?:?"1","_version"?:?1,"found"?:?true,"_source"?:?{"name"?:?"John?Doe"} }

可以看到_source的內(nèi)容就是我們剛才插入的數(shù)據(jù)。

本文由賽克藍德(secisland)原創(chuàng),轉(zhuǎn)載請標(biāo)明作者和出處。

修改數(shù)據(jù)

執(zhí)行:POST localhost:9200/customer/external/1/_update?pretty

參數(shù):

{"doc":?{?"name":?"secisland?Doe"?} }

返回結(jié)果:

{"_index"?:?"customer","_type"?:?"external","_id"?:?"1","_version"?:?2,"_shards"?:?{"total"?:?2,"successful"?:?1,"failed"?:?0} }

表示執(zhí)行成功。

然后我們在查詢一下數(shù)據(jù)

GET http://localhost:9200/customer/external/1?pretty

{"_index"?:?"customer","_type"?:?"external","_id"?:?"1","_version"?:?2,"found"?:?true,"_source"?:?{"name"?:?"secisland?Doe"} }

可以看出文檔的內(nèi)容由John Doe修改成了secisland?Doe。

刪除文檔

執(zhí)行:DELETE localhost:9200/customer/external/1?pretty

返回:

{"found"?:?true,"_index"?:?"customer","_type"?:?"external","_id"?:?"1","_version"?:?3,"_shards"?:?{"total"?:?2,"successful"?:?1,"failed"?:?0} }

然后我們查詢庫的狀態(tài):

GET http://localhost:9200/_cat/indices?v

返回:

health status index ? ?pri rep docs.count docs.deleted store.size pri.store.size?

yellow open ? customer ? 5 ? 1 ? ? ? ? ?0 ? ? ? ? ? ?0 ? ? ?3.6kb ? ? ? ? ?3.6kb?

從中可以看出,數(shù)據(jù)庫中已經(jīng)沒有記錄了。

刪除索引庫

執(zhí)行:DELETE localhost:9200/customer?pretty

返回:

{"acknowledged"?:?true }

表示刪除成功

然后我們查詢庫的狀態(tài):

GET http://localhost:9200/_cat/indices?v

返回:

health status index pri rep docs.count docs.deleted store.size pri.store.size?

從中可以看出已經(jīng)沒有任何的庫了。

賽克藍德(secisland)后續(xù)會逐步對Elasticsearch的最新版本的各項功能進行分析,近請期待。也歡迎加入secisland公眾號進行關(guān)注。

轉(zhuǎn)載于:https://my.oschina.net/secisland/blog/613927

總結(jié)

以上是生活随笔為你收集整理的Elasticsearch 2.20入门篇:基本操作的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。