批量查询 _mget

为了提升吞吐量,减少客户端与es服务端的交互,就有了批量查询。

_search批量查询:

还有一种批量查询是 _mget 

 返回数据:

{
	"docs": [
		{
			"_index": "shop",
			"_type": "_doc",
			"_id": "1001",
			"_version": 4,
			"_seq_no": 3,
			"_primary_term": 1,
			"found": true,
			"_source": {
				"id": 1001,
				"age": 18,
				"username": "imoocAmazing",
				"nickname": "慕课网",
				"money": 88.8,
				"desc": "我在慕课网学习java和前端, 学习到了很多知识",
				"sex": 0,
				"birthday": "1922-12-24",
				"face": "https://www.imooc.com/static/img/index/logo.png"
			}
		},
		{
			"_index": "shop",
			"_type": "_doc",
			"_id": "1003",
			"_version": 1,
			"_seq_no": 3,
			"_primary_term": 1,
			"found": true,
			"_source": {
				"id": 1003,
				"age": 20,
				"username": "bigFace",
				"nickname": "飞翔的巨鹰",
				"money": 66.8,
				"desc": "慕课网团队和导游坐飞机去海外旅游,去了新马泰和欧洲",
				"sex": 1,
				"birthday": "1996-01-14",
				"face": "https://www.imooc.com/static/img/index/logo.png"
			}
		},
		{
			"_index": "shop",
			"_type": "_doc",
			"_id": "1006",
			"_version": 2,
			"_seq_no": 14,
			"_primary_term": 2,
			"found": true,
			"_source": {
				"id": 1006,
				"age": 19,
				"username": "missimooc",
				"nickname": "我叫小慕",
				"money": 156.8,
				"desc": "我叫凌云慕,今年20岁,是一名律师,我在奇䯲星球做演讲",
				"sex": 1,
				"birthday": "1993-04-14",
				"face": "https://www.imooc.com/static/img/index/logo.png"
			}
		}
	]
}

可以看到_mget批量查询获取的数据比_search批量查询获取的数据内容少了一些原数据信息。_mget多了一个字段:found,found为true,表示这个文档存在,false表示不存在。而用_search查询,不存在的数据不会返回。

演示1:_search查询,不存在的数据不会返回。id="1234"不存在。

 返回数据:

{
	"took": 2,
	"timed_out": false,
	"_shards": {
		"total": 3,
		"successful": 3,
		"skipped": 0,
		"failed": 0
	},
	"hits": {
		"total": {
			"value": 2,
			"relation": "eq"
		},
		"max_score": 1,
		"hits": [
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1003",
				"_score": 1,
				"_source": {
					"id": 1003,
					"age": 20,
					"username": "bigFace",
					"nickname": "飞翔的巨鹰",
					"money": 66.8,
					"desc": "慕课网团队和导游坐飞机去海外旅游,去了新马泰和欧洲",
					"sex": 1,
					"birthday": "1996-01-14",
					"face": "https://www.imooc.com/static/img/index/logo.png"
				}
			},
			{
				"_index": "shop",
				"_type": "_doc",
				"_id": "1001",
				"_score": 1,
				"_source": {
					"id": 1001,
					"age": 18,
					"username": "imoocAmazing",
					"nickname": "慕课网",
					"money": 88.8,
					"desc": "我在慕课网学习java和前端, 学习到了很多知识",
					"sex": 0,
					"birthday": "1922-12-24",
					"face": "https://www.imooc.com/static/img/index/logo.png"
				}
			}
		]
	}
}

演示2:_mget查询,不存在的数据还会返回其json结构 。id="1234"不存在。

 返回数据:

{
	"docs": [
		{
			"_index": "shop",
			"_type": "_doc",
			"_id": "1001",
			"_version": 4,
			"_seq_no": 3,
			"_primary_term": 1,
			"found": true,
			"_source": {
				"id": 1001,
				"age": 18,
				"username": "imoocAmazing",
				"nickname": "慕课网",
				"money": 88.8,
				"desc": "我在慕课网学习java和前端, 学习到了很多知识",
				"sex": 0,
				"birthday": "1922-12-24",
				"face": "https://www.imooc.com/static/img/index/logo.png"
			}
		},
		{
			"_index": "shop",
			"_type": "_doc",
			"_id": "1003",
			"_version": 1,
			"_seq_no": 3,
			"_primary_term": 1,
			"found": true,
			"_source": {
				"id": 1003,
				"age": 20,
				"username": "bigFace",
				"nickname": "飞翔的巨鹰",
				"money": 66.8,
				"desc": "慕课网团队和导游坐飞机去海外旅游,去了新马泰和欧洲",
				"sex": 1,
				"birthday": "1996-01-14",
				"face": "https://www.imooc.com/static/img/index/logo.png"
			}
		},
		{
			"_index": "shop",
			"_type": "_doc",
			"_id": "1234",
			"found": false
		}
	]
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

@所谓伊人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值