16、分布式文档系统--document的_source元数据以及定制返回结果解析(来自学习资料+自己整理)

1、_source元数据

准备一条数据

put /test_index/test_type/1
{
  "test_field1": "test field1",
  "test_field2": "test field2"
}

然后获取数据

get /test_index/test_type/1

显示的结果是:

{
  "_index": "test_index",
  "_type": "test_type",
  "_id": "1",
  "_version": 2,
  "found": true,
  "_source": {
    "test_field1": "test field1",
    "test_field2": "test field2"
  }
}

知识点:
_source元数据:就是说,我们在创建一个document的时候,使用的是那个放在request body的json串。默认情况下,在get的时候,会原封不动的返回回来。

为了能够定制返回的结果,可以使用下面的方式:

2、定制返回结果

定制返回的结果,是通过指定_source,然后写上返回哪些field来实现。
命令:

GET /test_index/test_type/1?_source=test_field1

返回内容是:

{
  "_index": "test_index",
  "_type": "test_type",
  "_id": "1",
  "_version": 2,
  "found": true,
  "_source": {
    "test_field1": "test field1"
  }
}

如果想指定多列,命令如下:

GET /test_index/test_type/1?_source=test_field1,test_field2

结果如下:

{
  "_index": "test_index",
  "_type": "test_type",
  "_id": "1",
  "_version": 2,
  "found": true,
  "_source": {
    "test_field1": "test field1",
    "test_field2": "test field2"
  }
}

也就是说,可以通过逗号,然后加上列名即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

涂作权的博客

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

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

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

打赏作者

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

抵扣说明:

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

余额充值