I have an elasticsearch database that I access through a node.js client. I can parse the JSON from elasticsearch to print out the hitsArray which looks like below:
[ { _index: 'parties',
_type: 'suppliers',
_id: 'AV0uELknL82XeGsCOZ-i',
_score: 1,
_source: { name: 'Jabil', address: [Object], rating: 4.2 } },
{ _index: 'parties',
_type: 'suppliers',
_id: 'AV0t_yC3L82XeGsCOZ-f',
_score: 1,
_source: { name: 'Apple', address: [Object], rating: 4.9 } },
{ _index: 'parties',
_type: 'suppliers',
_id: 'AV0t_glkL82XeGsCOZ-d',
_score: 1,
_source: { name: 'Flextronics', address: [Object], rating: 4.5 } },
{ _index: 'parties',
_type: 'suppliers',
_id: 'AV0t_ox7L82XeGsCOZ-e',
_score: 1,
_source: { name: 'FlashMob', address: [Object], rating: 3.5 } } ]
Now, I want to parse the _source field and print out the name field
client.search(searchParams).then(function (resp) {
return Promise.all(resp.hits.hits)
}).then(function(hitsArray){
hitsArray.forEach(function(value){
JSONObject first = hitsArray.getJSONObject(value);
JSONObject source = first.getJSONObject("_source");
String name = source.getString("name");
console.log(name);
});
});
But I am getting error
JSONObject first = hitsArray.getJSONObject(value);
^^^^^
SyntaxError: Unexpected identifier
What am I missing? any suggestion?