每天进步一点点~~
https://geek-docs.com/python/python-ask-answer/605_python_looping_through_a_json_array_in_python.html
{'took': 0, 'timed_out': False, '_shards': {'total': 5, 'successful': 5, 'failed': 0}, 'hits': {'total': 3, 'max_score': 3.3322046, 'hits': [{'_index': 'high_disp_retrieve_two_month_new', '_type': 'high_disp_retrieve_two_month_n
ew', '_id': 'AY0anzQGS_kZwf29X-kh', '_score': 3.3322046, '_source': {'inc_month': '202401', 'mobile_secret': 'mobile_no', 'user_group': 'P4', 'dec_type': 'real', 'task1_id': 'T1', 'task1_num': 2, 'task1_AB
_coupon': 'A', 'task2_id': 'T2', 'task2_num': 4, 'task2_AB_coupon': 'A', 'task3_id': 'T3', 'task3_num': 8, 'task3_AB_coupon': 'A', 'send_num': '35', 'model_type': '付款'}}, {'_index': 'high_disp_retrieve_two_month_new', '_type':
'high_disp_retrieve_two_month_new', '_id': 'AY0WNGvFS_kZwf29X-kN', '_score': 2.7725887, '_source': {'inc_month': '202310', 'mobile_secret': 'mobile_no', 'user_group': 'P2', 'dec_type': 'real', 'task1_id':
'T1', 'task1_num': 3, 'task1_AB_coupon': 'A', 'task2_id': 'T2', 'task2_num': 8, 'task2_AB_coupon': 'A', 'task3_id': 'T3', 'task3_num': 20, 'task3_AB_coupon': 'A', 'send_num': '35', 'model_type': '寄件'}}, {'_index': 'high_disp_
retrieve_two_month_new', '_type': 'high_disp_retrieve_two_month_new', '_id': 'AY0XC3-xS_kZwf29X-kd', '_score': 2.7725887, '_source': {'inc_month': '202312', 'mobile_secret': 'mobile_no', 'user_group': 'S1'
, 'dec_type': 'real', 'task1_id': 'T1', 'task1_num': 0, 'task1_AB_coupon': 'A', 'task2_id': 'T2', 'task2_num': 0, 'task2_AB_coupon': 'A', 'task3_id': 'T3', 'task3_num': 0, 'task3_AB_coupon': 'A', 'send_num': '35', 'model_type':
'寄件'}}]}}
# 获取返回值,根据 key 值将需要的内容打印出来
r=requests.post(url=url,json=json_data)
result=r.json()
print(result)
print(result['hits']['hits'])
# for 循环遍历结果中的 id 值,返回 id 值给删除接口做入参使用
for _id in result['hits']['hits']:
id = _id['_id']
print(id)
return id
def test_deleteabnoaldata(self):
url='http://high_disp_retrieve_two_month_new/high_disp_retrieve_two_month_new'
delete_data=requests.delete(url=url + '/' + self.test_searchdata())
delete_result=delete_data.json()
assert delete_result['result'] == 'deleted'
print(delete_result)