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"
  }
}

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

猜你喜欢

转载自blog.csdn.net/toto1297488504/article/details/80558212
今日推荐