Hi i am working on angular15, here i have got json data like this and i have to bring data for address along with profileName, so my response should be like:
Expected Result:
[
{name:'Pharmarx Pharmaceutical Inc', address:'21441 Osborne St Ste C & D, Canoga Park, CA, 91304'},
{name:'Pharmarx Pharmaceutical Inc', address:'441 abc address, Canoga Park, CA, 91304'},
{name:'Pharmarx Pharmaceutical Inc', address:'231 osborne, Canoga Park, CA, 91304'},
{name:'Pharmarx Pharmaceutical Inc', address:'987 osborneOsborne St Ste C & D, Canoga Park, CA, 91304'},
{name:'ENCINO PHARMACY_AKA MDR PHARMACEUTICAL CARE', address:'17071 VENTURA BLVD STE 100 ECINO, MI,91316'}
]
Json:
{
"took": 178,
"timed_out": false,
"_shards": {
"total": 0,
"successful": 0,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 10000,
"relation": "gte"
},
"max_score": 12.9226,
"hits": [
{
"_index": "pulse",
"_id": "17320",
"_score": 12.9226,
"_source": {
"ProfileName": "Pharmarx Pharmaceutical Inc",
"BusinessModel": "Dispenser",
"LicenseInfo": [
{
"LicenseType": "Resident Licensed Sterile Compounding",
"LicenseNumber": "99658",
"AddressLine1": "21441 Osborne St Ste C & D",
"AddressLine2": "441 abc address",
"AddressLine3": "231 osborne",
"AddressLine4": "",
"Zip": "91304",
"City": "Canoga Park",
"State": "CA",
},
{
"LicenseType": "Retail Pharmacy",
"LicenseNumber": "50511",
"AddressLine1": "21441 Osborne St Ste C & D",
"AddressLine2": "987 osborne",
"AddressLine3": "",
"AddressLine4": "",
"Zip": "91304",
"City": "Canoga Park"
}
]
}
},
{
"_index": "pulse",
"_id": "7723",
"_score": 10.891928,
"_source": {
"ProfileName": "ENCINO PHARMACY_AKA MDR PHARMACEUTICAL CARE",
"State": "MI",
"BusinessModel": "Dispenser",
"LicenseInfo": [
{
"LicenseType": "PHARMACY",
"LicenseNumber": "5301010993",
"AddressLine1": "17071 VENTURA BLVD STE 100",
"AddressLine2": "",
"AddressLine3": "",
"AddressLine4": "",
"Zip": "91316",
"City": "ENCINO"
}
]
}
},
{
"_index": "pulse",
"_id": "7724",
"_score": 9.796367,
"_source": {
"ProfileName": "Encino Pharmacy_aka Mdr Pharmaceutical Care",
"State": "CA",
"BusinessModel": "Dispenser",
"LicenseInfo": [
{
"LicenseType": "Retail Pharmacy",
"LicenseNumber": "34818",
"AddressLine1": "17059-17071 VENTURA BLVD.",
"AddressLine2": "STE. 100",
"AddressLine3": "",
"AddressLine4": "",
"Zip": "91316",
"City": "ENCINO"
}
]
}
},
{
"_index": "pulse",
"_id": "192",
"_score": 9.656487,
"_source": {
"ProfileName": "Abdin Pharmacies Pharma LLC",
"State": "FL",
"BusinessModel": "Dispenser",
"LicenseInfo": [
{
"LicenseType": "Pharmacy",
"LicenseNumber": "036936",
"AddressLine1": "1873 SECOND AVE. NEW",
"AddressLine2": "",
"AddressLine3": "",
"AddressLine4": "",
"Zip": "10029",
"City": "YORK"
},
{
"LicenseType": "Pharmacy",
"LicenseNumber": "033404",
"AddressLine1": "1401 BRONX RIVER AVE.",
"AddressLine2": "",
"AddressLine3": "",
"AddressLine4": "",
"Zip": "10472",
"City": "BRONX"
},
{
"LicenseType": "Pharmacy",
"LicenseNumber": "PH33043",
"AddressLine1": "32866 US Hwy 19N",
"AddressLine2": "",
"AddressLine3": "",
"AddressLine4": "",
"Zip": "34684",
"City": "PALM HARBOR"
}
]
}
},
{
"_index": "pulse",
"_id": "17304",
"_score": 9.186218,
"_source": {
"ProfileName": "PHARMALABS, LLC PharmaLabs",
"State": "FL",
"BusinessModel": "Dispenser",
"LicenseInfo": [
{
"LicenseType": "Pharmacy",
"LicenseNumber": "PH26495",
"AddressLine1": "10901 ROOSEVELT BOULEVARD NORTH SUITE 1200",
"AddressLine2": "",
"AddressLine3": "",
"AddressLine4": "",
"Zip": "33716",
"City": "Saint Petersburg"
}
]
}
}
]
}
}
Ts:
results = searchData.hits;
if (results.hits.length > 0) {
results.hits.forEach(h => {
let item = h._source;
item.LicenseInfo.forEach(ap => {
let address = `${ap.AddressLine1} ${ap.AddressLine2} ${ap.AddressLine3} ${ap.AddressLine4} ${ap.City} ${item.State} ${ap.Zip}`;
let addresses = { name: item.ProfileName, address }
data = data.concat(addresses);
})
this.seeResultsData = data;
return data;
})
return null;
}
now, i am getting this.seeResultsData as
Currently i am getting:
[
{name:'Pharmarx Pharmaceutical Inc', address:'21441 Osborne St Ste C & D 441 abc address 231 osborne 987 osborneOsborne St Ste C & D, Canoga Park, CA, 91304'},
{name:'ENCINO PHARMACY_AKA MDR PHARMACEUTICAL CARE', address:'17071 VENTURA BLVD STE 100 ECINO, MI,91316'}
]
2
Answers
In order to get all the adresses, you could try something like this:
output