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

歡迎訪問(wèn) 生活随笔!

生活随笔

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

编程问答

Elasticsearch技术解析与实战(七)Elasticsearch批量操作

發(fā)布時(shí)間:2024/1/17 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Elasticsearch技术解析与实战(七)Elasticsearch批量操作 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

批量查詢(xún)

1.如果查詢(xún)的document是不同index下的不同type種的話

GET /_mget {"docs" : [{"_index" : "test_index","_type" : "test_type","_id" : 1},{"_index" : "test_index","_type" : "test_type","_id" : 2}] }

2.如果查詢(xún)的document是一個(gè)index下的不同type種的話

GET /test_index/_mget {"docs" : [{"_type" : "test_type","_id" : 1},{"_type" : "test_type","_id" : 2}] }

3.如果查詢(xún)的數(shù)據(jù)都在同一個(gè)index下的同一個(gè)type下,最簡(jiǎn)單了

GET /test_index/test_type/_mget {"ids": [1, 2] }

mget的重要性:

? 可以說(shuō)mget是很重要的,一般來(lái)說(shuō),在進(jìn)行查詢(xún)的時(shí)候,如果一次性要查詢(xún)多條數(shù)據(jù)的話,那么一定要用batch批量操作的api

? 盡可能減少網(wǎng)絡(luò)開(kāi)銷(xiāo)次數(shù),可能可以將性能提升數(shù)倍,甚至數(shù)十倍,非常非常之重要

bulk語(yǔ)法

??bulk api對(duì)json的語(yǔ)法,有嚴(yán)格的要求,每個(gè)json串不能換行,只能放一行,同時(shí)一個(gè)json串和一個(gè)json串之間,必須有一個(gè)換行

? bulk操作中,任意一個(gè)操作失敗,是不會(huì)影響其他的操作的,但是在返回結(jié)果里,會(huì)告訴你異常日志

第一種

POST /_bulk { "delete": { "_index": "test_index", "_type": "test_type", "_id": "3" }} { "create": { "_index": "test_index", "_type": "test_type", "_id": "12" }} { "test_field": "test12" } { "index": { "_index": "test_index", "_type": "test_type", "_id": "2" }} { "test_field": "replaced test2" } { "update": { "_index": "test_index", "_type": "test_type", "_id": "1", "_retry_on_conflict" : 3} } { "doc" : {"test_field2" : "bulk test1"} }

第二種

POST /test_index/_bulk { "delete": { "_type": "test_type", "_id": "3" }} { "create": { "_type": "test_type", "_id": "12" }} { "test_field": "test12" } { "index": { "_type": "test_type" }} { "test_field": "auto-generate id test" } { "index": { "_type": "test_type", "_id": "2" }} { "test_field": "replaced test2" } { "update": { "_type": "test_type", "_id": "1", "_retry_on_conflict" : 3} } { "doc" : {"test_field2" : "bulk test1"} }

第三種

POST /test_index/test_type/_bulk { "delete": { "_id": "3" }} { "create": { "_id": "12" }} { "test_field": "test12" } { "index": { }} { "test_field": "auto-generate id test" } { "index": { "_id": "2" }} { "test_field": "replaced test2" } { "update": { "_id": "1", "_retry_on_conflict" : 3} } { "doc" : {"test_field2" : "bulk test1"} }

bulk size最佳大小

? bulk request會(huì)加載到內(nèi)存里,如果太大的話,性能反而會(huì)下降,因此需要反復(fù)嘗試一個(gè)最佳的bulk size。一般從1000~5000條數(shù)據(jù)開(kāi)始,嘗試逐漸增加。另外,如果看大小的話,最好是在5~15MB之間。

總結(jié)

以上是生活随笔為你收集整理的Elasticsearch技术解析与实战(七)Elasticsearch批量操作的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

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