问答详情
源自:6-5 更新接口开发

查询没有返回id字段

请问这个是配置的问题,还是其他原因

提问者:偏见 2018-01-21 17:19

个回答

  • 慕移动9181930
    2022-03-25 12:42:58

    在试一试最好用chrome浏览器吆。flag=1playFun()flag=0stopFun()

  • CorningSun
    2018-03-06 10:40:14

    // 查询接口
    @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
    }