从httpClient JSON响应中缺少字段

时间:2016-11-11 22:00:56

标签: java json elasticsearch

所以我试图从我从Web应用程序获取的查询中复制JSON响应,而不是通过Java中的httpClient复制。

但是,缺少我想要的JSONObject“fields”值。

在我的浏览器上,我收到了此回复

    {
   "took": 6,
   "timed_out": false,
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "hits": {
      "total": 1,
      "max_score": 1,
      "hits": [
         {
            "_index": "jump_geography",
            "_type": "da",
            "_id": "48111445",
            "_score": 1,
            "fields": {
               "properties.CTUID": [
                  8350075.02
               ]
            }
         }
      ]
   }
}

然而,在实现我的代码之后,我得到的回复

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "failed": 0
  },
  "hits": {
    "total": 1,
    "max_score": 1,
    "hits": [
      {
        "_index": "jump_geography",
        "_type": "da",
        "_id": "48111445",
        "_score": 1
      }
    ]
  }
}

基本上,这是我用过的代码

    String urlParams = "{\"query\": {\"geo_shape\": {\"geometry\": {\"shape\": {\"type\": \"point\", \"coordinates\": [\""
            + longitude + "\", \"" + latitude + "\"]}}}}}";

    HttpClient httpClient = HttpClientBuilder.create().build();
    HttpPost request = new HttpPost(targetURL);

    StringEntity params = new StringEntity(urlParams);
    request.setEntity(params);
    request.setHeader(
            "User-Agent",
            "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36");

    HttpResponse response = httpClient.execute(request);

感谢您的帮助

0 个答案:

没有答案