查询没有返回id字段
请问这个是配置的问题,还是其他原因
请问这个是配置的问题,还是其他原因
2018-01-21
// 查询接口
@GetMapping("/get/book/novel")
public ResponseEntity get(@RequestParam(name = "id", defaultValue = "") String id) {
GetResponse response = client.prepareGet(BOOK_INDEX, BOOK_TYPE_NOVEL, id).get();
if (!response.isExists()) {
return new ResponseEntity(HttpStatus.NOT_FOUND);
}
return new ResponseEntity(response.getSource(), HttpStatus.OK);
}id存储在 GetResponse response 中,而示例里面,返回的是 response.getSource() ,具体结构可以自己debug看一下。
如果直接返回 GetResponse response 对象,那么得到的结果如下:
{
"fields": {},
"id": "1",
"type": "novel",
"index": "book",
"source": {
"word_count": 5000,
"author": "王五",
"title": "超级菜谱",
"publish_date": "2002-10-01"
},
"version": 2,
"exists": true,
"sourceAsMap": {
"word_count": 5000,
"author": "王五",
"title": "超级菜谱",
"publish_date": "2002-10-01"
},
"sourceEmpty": false,
"sourceAsBytesRef": {
"childResources": []
},
"sourceAsBytes": "eyJhdXRob3IiOiLnjovkupQiLCJ0aXRsZSI6Iui2hee6p+iPnOiwsSIsIndvcmRfY291bnQiOjUwMDAsInB1Ymxpc2hfZGF0ZSI6IjIwMDItMTAtMDEifQ==",
"sourceInternal": {
"childResources": []
},
"sourceAsString": "{\"author\":\"王五\",\"title\":\"超级菜谱\",\"word_count\":5000,\"publish_date\":\"2002-10-01\"}",
"fragment": false
}举报