2
私は、私のローカルドライブに保存されているファイルにElasticsearchのjsonデータを保存しています。代わりに、Arraylistにデータを保存したいので、UIに渡してフロントエンドに表示することができます。Arraylistにjsonデータを保存するには?
try {
HttpGet request = new HttpGet("http://localhost:9200/indexname/_search?pretty=1&size=100&q=name:%22Test%22");
HttpResponse resp = client.execute(request);
HttpEntity entity = resp.getEntity();
byte[] buffer = new byte[1024];
if (entity != null) {
InputStream input = entity.getContent();
FileWriter file = new FileWriter("/localpath/data.json");
try {
int bytesRead = 0;
BufferedInputStream in = new BufferedInputStream(input);
while ((bytesRead = in.read(buffer)) != -1) {
String chunk = new String(buffer, 0, bytesRead);
System.out.println(chunk);
file.write(chunk);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try { file.close(); inputStream.close(); } catch (Exception ignore) {}
}
}
}
JSONデータは、フォーマットは次のとおりです。私のArrayListで
{
"took": 9,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 6.3519955,
"hits": [
{
"_index": "indexname",
"_type": "status",
"_id": "eb825358-93d7-4a2f-9227-9b060cbc323a",
"_score": 6.3519955,
"_source": {
"name": "Test",
"ID": "ABCD",
"Number": "23222",
"SecCode": "124"
}
},
{
"_index": "indexname",
"_type": "status",
"_id": "eb825358-93d7-4a2f-9227-9b060cbc323b",
"_score": 6.3519955,
"_source": {
"name": "Test",
"ID": "CDEF",
"Number": "5678",
"SecCode": "120"
}
}
]
}
}
が、私はIDと番号のを保存したいです。
助けていただけたら幸いです。ありがとう