Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

elasticsearch dsl scan results

Can someone point me to how to extract the results _source from the generator when using the scan API in the elasticsearch dsl python client?

for example, i'm using (from this example, elasticsearch-dsl scan)

for hit in s.scan():
    print(hit)

I get the following

<Hit(beacon/INDEX/_Mwt9mABoXXeYV0uwSC-): {'client_number': '3570', 'cl...}>

How do I extract the dictionary from the hit generator?

like image 807
Arun Ramachandran Avatar asked Jan 03 '23 11:01

Arun Ramachandran


1 Answers

Every Hit has to_dict(), hence you can just do hit.to_dict():

for hit in s.scan():
    print(hit.to_dict())

Note: hit.to_dict() doesn't convert meta info, you can get the meta from the meta object, i.e.:

hit_dict = hit.to_dict()
hit_dict['meta'] = hit.meta.to_dict()
like image 101
Ami Hollander Avatar answered Jan 05 '23 16:01

Ami Hollander