Skip to content

Getting started example in the docs needs to be updated for v7 #922

@elyase

Description

@elyase

The starting example in the docs doesn't work:

image

The part:

res = es.search(index="test-index", body={"query": {"match_all": {}}})
print("Got %d Hits:" % res['hits']['total'])
for hit in res['hits']['hits']:
    print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])

fails with:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-21-41126016e65f> in <module>
     17 
     18 res = es.search(index="test-index", body={"query": {"match_all": {}}})
---> 19 print("Got %d Hits:" % res['hits']['total'])
     20 for hit in res['hits']['hits']:
     21     print("%(timestamp)s %(author)s: %(text)s" % hit["_source"])

TypeError: %d format: a number is required, not dict

and needs to be replaced with:

print("Got %d Hits:" % res['hits']['total']['value'])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions