我正在從ElasticSearch獲得響應,從該響應中我想形成另一個字段有限的JSON(例如自定義JSONObject)。請找到通過彈性搜索得到的響應。{ "took":93, "timed_out":false, "_shards":{ "total":5, "successful":5, "skipped":0, "failed":0 }, "hits":{ "total":1, "max_score":1.0, "hits":[ { "_index":"attachment", "_type":"doc", "_id":"87740", "_score":1.0, "_source":{ "app_language":"ES", "filetype":"PB", "attachment":{ "date":"2006-05-03T15:17:53Z", "content_type":"application/pdf", "author":"JJamesN", "language":"en", "title":"Microsoft Word - te7000pb.doc", "content":"European Electronic Controls Catalog ", "content_length":12267 }, "ext":"pdf", "fileContent":"JVBERi0xLjQNJeLjz9MNCjQ3ID" } } ] }}請找到我的Java代碼,該Java代碼試圖操縱響應JSON以創建具有有限字段的單獨JSON。JSONObject jsonObject = new JSONObject(responseBody);JSONObject hits = jsonObject.getJSONObject("hits");JSONArray hitsArray=hits.getJSONArray("hits");System.out.println("Hits---->"+hitsArray.toString());從響應JSON,我只想使用以下結構和字段創建一個新的JSON。 { "app_language":"ES", "filetype":"PB", "attachment.content" : "European Electronic Controls Catalog ", "ext":"pdf", }
根據彈性搜索的JSON響應形成自定義JSON對象
慕的地6264312
2021-04-16 18:16:32
