{'_id': 'wZQlBGoBENgcYA5dUvr_',
'_index': 'fh_images',
'_score': 0.3617011156311892,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c9318/u298156/-6/y_84164775.jpg'},
'_type': 'fh_image'}
{'_id': 'wpQlBGoBENgcYA5dV_pJ',
'_index': 'fh_images',
'_score': 0.44313779433299844,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c11125/u298156/125130624/y_1d015950.jpg'},
'_type': 'fh_image'}
{'_id': 'x5QlBGoBENgcYA5da_pJ',
'_index': 'fh_images',
'_score': 0.44582819825057535,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c4475/u298156/-6/y_32e0b727.jpg'},
'_type': 'fh_image'}
{'_id': 'w5QlBGoBENgcYA5dWvrP',
'_index': 'fh_images',
'_score': 0.45485040641214125,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c11125/u298156/125130624/y_80599d36.jpg'},
'_type': 'fh_image'}
{'_id': 'xJQlBGoBENgcYA5dXvrv',
'_index': 'fh_images',
'_score': 0.4625495354012009,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c9318/u298156/125130624/y_ab5d368d.jpg'},
'_type': 'fh_image'}
{'_id': 'xpQlBGoBENgcYA5dZ_pU',
'_index': 'fh_images',
'_score': 0.4636520489656735,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c11187/u298156/-6/y_8e5cdd46.jpg'},
'_type': 'fh_image'}
{'_id': 'xZQlBGoBENgcYA5dY_oi',
'_index': 'fh_images',
'_score': 0.5156954172925243,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c4422/u298156/-6/y_8458ec16.jpg'},
'_type': 'fh_image'}
{'_id': 'xJQKBGoBENgcYA5dKvQ5',
'_index': 'fh_images',
'_score': 0.5572724509457869,
'_source': {'img_id': '299217',
'img_url': 'https://img.com/c10739/u299217/-6/y_19eb9a0c.jpg'},
'_type': 'fh_image'}
{'_id': 's5QgBGoBENgcYA5dtPla',
'_index': 'fh_images',
'_score': 0.5624892892097831,
'_source': {'img_id': '298711',
'img_url': 'https://img.com/c308425/v308425711/3c/UJdRfCsT3fs.jpg'},
'_type': 'fh_image'}
{'_id': 'qpQpBGoBENgcYA5dyvui',
'_index': 'fh_images',
'_score': 0.5646689160902589,
'_source': {'img_id': '298039',
'img_url': 'https://img.com/c5786/u298039/-6/y_e3bc7d5c.jpg'},
'_type': 'fh_image'}
obj = [
{'_id': 'wZQlBGoBENgcYA5dUvr_',
'_index': 'fh_images',
'_score': 0.3617011156311892,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c9318/u298156/-6/y_84164775.jpg'},
'_type': 'fh_image'},
{'_id': 'wpQlBGoBENgcYA5dV_pJ',
'_index': 'fh_images',
'_score': 0.44313779433299844,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c11125/u298156/125130624/y_1d015950.jpg'},
'_type': 'fh_image'},
{'_id': 'x5QlBGoBENgcYA5da_pJ',
'_index': 'fh_images',
'_score': 0.44582819825057535,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c4475/u298156/-6/y_32e0b727.jpg'},
'_type': 'fh_image'},
{'_id': 'w5QlBGoBENgcYA5dWvrP',
'_index': 'fh_images',
'_score': 0.45485040641214125,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c11125/u298156/125130624/y_80599d36.jpg'},
'_type': 'fh_image'},
{'_id': 'xJQlBGoBENgcYA5dXvrv',
'_index': 'fh_images',
'_score': 0.4625495354012009,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c9318/u298156/125130624/y_ab5d368d.jpg'},
'_type': 'fh_image'},
{'_id': 'xpQlBGoBENgcYA5dZ_pU',
'_index': 'fh_images',
'_score': 0.4636520489656735,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c11187/u298156/-6/y_8e5cdd46.jpg'},
'_type': 'fh_image'},
{'_id': 'xZQlBGoBENgcYA5dY_oi',
'_index': 'fh_images',
'_score': 0.5156954172925243,
'_source': {'img_id': '298156',
'img_url': 'https://img.com/c4422/u298156/-6/y_8458ec16.jpg'},
'_type': 'fh_image'},
{'_id': 'xJQKBGoBENgcYA5dKvQ5',
'_index': 'fh_images',
'_score': 0.5572724509457869,
'_source': {'img_id': '299217',
'img_url': 'https://img.com/c10739/u299217/-6/y_19eb9a0c.jpg'},
'_type': 'fh_image'},
{'_id': 's5QgBGoBENgcYA5dtPla',
'_index': 'fh_images',
'_score': 0.5624892892097831,
'_source': {'img_id': '298711',
'img_url': 'https://img.com/c308425/v308425711/3c/UJdRfCsT3fs.jpg'},
'_type': 'fh_image'},
{'_id': 'qpQpBGoBENgcYA5dyvui',
'_index': 'fh_images',
'_score': 0.5646689160902589,
'_source': {'img_id': '298039',
'img_url': 'https://img.com/c5786/u298039/-6/y_e3bc7d5c.jpg'},
'_type': 'fh_image'},
]
import json
from itertools import groupby
result = {
k: [(sub_obj['_score'], sub_obj['_source']['img_url']) for sub_obj in values]
for k, values in groupby(obj, key=lambda x: x['_source']['img_id'])
}
print(json.dumps(result, indent=4))