document的_source元数据以及定制返回结果解析

document的_source元数据以及定制返回结果解析

1._source元数据

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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"
}
}

2.定制返回结果

定制返回的结果,指定_source中,返回哪些field

eg:?_source=key1,key2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
1. 
GET /test_index/test_type/1?_source=test_field1
{
"_index": "test_index",
"_type": "test_type",
"_id": "1",
"_version": 2,
"found": true,
"_source": {
"test_field2": "test field2"
}
}
2.
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_field2": "test field2"
}
}
打赏
  • 版权声明: 本博客所有文章除特别声明外,著作权归作者所有。转载请注明出处!
  • © 2020 John Doe
  • Powered by Hexo Theme Ayer
  • PV: UV:

请我喝杯咖啡吧~

支付宝
微信