elasticsearch学习笔记(十六)——Elasticsearch mget批量查询api实战
首先说明一下为什么需要批量查询操作?
假设一下比如说我们没有批量查询的操作,那么当我们获取数据的时候,就是一条一条的查询。设想一下我们要获取100条数据,那么就要发送100次请求,这个开销时很大的。但是有了批量查询的话,查询100条数据,就只需要发送一次网络请求就可以了,网络请求的性能开销缩减100倍。
下面是实战部分,演示一下一条一条查询与批量查询:
(1)一条一条查询
GET /test_index/_doc/1
{
"_index" : "test_index",
"_type" : "_doc",
"_id" : "1",
"_version" : 8,
"_seq_no" : 7,
"_primary_term" : 1,
"found" : true,
"_source" : {
"test_field" : "test test",
"name" : "test1"
}
}
GET /test_index/_doc/2
{
"_index" : "test_index",
"_type" : "_doc",
"_id" : "2",
"_version" : 4,
"_seq_no" : 3,
"_primary_term" : 1,
"found" : true,
"_source" : {
"test_field" : "test client 1",
"name" : "test1"
}
}(2)mget批量查询
GET /_mget
{
"docs": [
{
"_index": "test_index",
"_id": 1
},
{
"_index": "test_index",
"_id": 2
}
]
}
{
"docs" : [
{
"_index" : "test_index",
"_type" : "_doc",
"_id" : "1",
"_version" : 8,
"_seq_no" : 7,
"_primary_term" : 1,
"found" : true,
"_source" : {
"test_field" : "test test",
"name" : "test1"
}
},
{
"_index" : "test_index",
"_type" : "_doc",
"_id" : "2",
"_version" : 4,
"_seq_no" : 3,
"_primary_term" : 1,
"found" : true,
"_source" : {
"test_field" : "test client 1",
"name" : "test1"
}
}
]
} 相关推荐
newbornzhao 2020-09-14
做对一件事很重要 2020-09-07
renjinlong 2020-09-03
明瞳 2020-08-19
李玉志 2020-08-19
mengyue 2020-08-07
molong0 2020-08-06
AFei00 2020-08-03
molong0 2020-08-03
wenwentana 2020-08-03
YYDU 2020-08-03
另外一部分,则需要先做聚类、分类处理,将聚合出的分类结果存入ES集群的聚类索引中。数据处理层的聚合结果存入ES中的指定索引,同时将每个聚合主题相关的数据存入每个document下面的某个field下。
sifeimeng 2020-08-03
心丨悦 2020-08-03
liangwenrong 2020-07-31
sifeimeng 2020-08-01
mengyue 2020-07-30
tigercn 2020-07-29
IceStreamLab 2020-07-29