2
Yerel sürücümde depolanan bir dosyada Elastic Search'ten json verilerini sakladığım şu kodu kullanıyorum. Bunun yerine, verileri bir Arraylist'te saklamak istiyorum, böylece bunu, ön uçta görüntülemek için UI'ye iletebilirim.Json verilerini bir Arraylist'te nasıl depolarsınız?
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 veri formatının geçerli: Benim arraylist olarak
{
"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"
}
}
]
}
}
, sadece kimlikleri ve Numarası en saklamak istiyorum.
Herhangi bir yardım için teşekkür ederiz?