[英]Forming custom JSON Object from the JSON response from elastic search
我正在从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",
}
尝试这个:
JSONObject jsonBody = new JSONObject();
jsonBody.put("app_language","value");
jsonBody.put("filetype","value");
jsonBody.put("attachment.content","value");
jsonBody.put("ext",ext);
//String requestBody = jsonBody.toString();
只需从响应中提取您的值,然后在任何需要的地方使用它即可。 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.