linux mget 模糊,elasticsearch mget bulk

multi get api

为了同时检索多个文档

# 同时获取多个文档信息

# 例子:获取index:bank, type:bank_account下面

# ID为1,2,3,4,15,6,28 的文档信息

GET /bank/bank_account/1

GET /bank/bank_account/2

GET /shakespeare/line/3

GET /bank/bank_account/4

GET /shakespeare/line/5

# 数组[]

GET /_mget

{

"docs" : [

{

"_index" : "bank",

"_type" :  "bank_account",

"_id" :    1

},

{

"_index" : "bank",

"_type" :  "bank_account",

"_id" :    2

},

{

"_index" : "shakespeare",

"_type" :  "line",

"_id" :    3

},

{

"_index" : "shakespeare",

"_type" :  "line",

"_id" :    4

},

{

"_index" : "shakespeare",

"_type" :  "line",

"_id" :    15

},

{

"_index" : "shakespeare",

"_type" :  "line",

"_id" :    6

},

{

"_index" : "shakespeare",

"_type" :  "line",

"_id" :    28

}

]

}

# 也可以指定_source字段,获取你想要的

GET /_mget

{

"docs" : [

{

"_index" : "shakespeare",

"_type" :  "line",

"_id" :    6,

"_source": "play_name"

},

{

"_index" : "shakespeare",

"_type" :  "line",

"_id" :    28,

"_source": "play_name"

}

]

}

# 指定多个_source字段,数组的形式[]

GET /_mget

{

"docs" : [

{

"_index" : "shakespeare",

"_type" :  "line",

"_id" :    6

},

{

"_index" : "shakespeare",

"_type" :  "line",

"_id" :    28,

"_source": ["play_name","speaker","text_entry"]

}

]

}

# 获取相同index相同type下不同ID的文档

GET /shakespeare/line/_mget

{

"docs" : [

{ "_id" : 6 },

{ "_type" : "line", "_id" :   28 }

]

}

# 可以这样简便的写

GET /shakespeare/line/_mget

{

"ids" : [ "6", "28" ]

}

GET /shakespeare/line/_mget

{

"ids" : [ "1", "2", "3", "4", "5", "6", "7" ]

}

# 多重模式

# 批量操作bulk

#为了实现多个文档的创建\更新\删除

#不能美化展示

POST /library/books/_bulk

{ "index":  { "_id": 1}}

{ "title":"Elasticsearch: The Definitive Guide","price":5 }

{ "index":  { "_id": 2}}

{ "title":"The Elasticsearch cookbook","price":15 }

{ "index":  { "_id": 3}}

{ "title":"Elasticsearch Blueprints","price":9 }

{ "index":  { "_id": 4}}

{ "title":"Thinking in Python","price":22 }

{ "index":  { "_id": 5}}

{ "title":"Thinking in Java","price":7 }

GET /library/

GET /library/books/_mget

{

"ids" : [ "1", "2" , "3", "4", "5"]

}

# 当然还可以有delete ,update等操作

# 注意delete下面没有具体的request body

POST /library/books/_bulk

{ "delete": { "_index": "library", "_type": "books", "_id": "1" }}

{ "create": { "_index": "music", "_type": "classical", "_id": "1" }}

{ "title": "Ave Verum Corpus" }

{ "index":  { "_index": "music", "_type": "classical" }}

{ "title": "Litaniac de Venerabili Altaris Sacromento" }

{ "update": { "_index": "library", "_type": "books", "_id": "2"} }

{ "doc" : {"price" : "18"} }

GET /library/books/1

GET /library/books/_mget

{

"ids" : [ "1", "2" , "3", "4", "5"]

}

bulk处理文档大小的最佳值

数据加载在每个节点的RAM中

请求数据超过一定大小,bulk处理性能会降低

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值