Reputation: 271
Pretty new to elasticsearch, and json in general.
I am using elasticsearch-dsl-py, here are the docs for search: https://github.com/elastic/elasticsearch-dsl-py/blob/master/docs/search_dsl.rst
here is sample code:
q = F("limit", value=1)
s = Account.search().filter(q)
response = s.execute()
for hit in response:
print hit
the above will return:
{'account': u'debug', 'proxy': u'127.0.0.1:8888', 'created_d...}
{'account': u'debug', 'proxy': u'127.0.0.1:8888', 'created_d...}
{'account': u'debug', 'proxy': u'127.0.0.1:8888', 'created_d...}
{'account': u'debug', 'proxy': u'127.0.0.1:8888', 'created_d...}
{'account': u'debug', 'proxy': u'127.0.0.1:8888', 'created_d...}
{'account': u'debug', 'proxy': u'127.0.0.1:8888', 'created_d...}
{'account': u'debug', 'proxy': u'127.0.0.1:8888', 'created_d...}
{'account': u'debug', 'proxy': u'127.0.0.1:8888', 'created_d...}
{'account': u'debug', 'proxy': u'127.0.0.1:8888', 'created_d...}
Don't understand why it's returning more than 1 result.
Upvotes: 2
Views: 3589
Reputation: 1007
Maybe an easier way to do what you're looking for is to use slices, which the Search class supports.
search = Account.search()
response = search[:1].execute()
for hit in response:
print hit
Upvotes: 2