How do i get the number of documents in an index in Marqo

79 views Asked by At

i would like to know if there is a way to get the number of documents i have added to an index in marqo, i have been adding docmunts to two different index but right now i don't know how many documents i have added to each. i tried doing this:

import marqo

mq = marqo.Client(url='http://localhost:8882')

first_index = mq.index("first-index").search(
    q="any_query"
    limit=100
)

second_index = mq.index("second-index").search(
    q="any_query"
    limit=100
)

print(len(first_index['hits']))
print(len(second_index['hits']))

this works because i know that the number of documents i have added is not upto 100. i would like to know if there is a more efficient way of getting the number of documents

1

There are 1 answers

0
Abubakarsq On

you can use the get_stats() method for that eg;

first_index_stats = mq.index("first-index").get_stats()

second_index_stats = mq.index("second-index").get_stats()

print(first_index_stats)
print(second_index_stats)

output;

{'numberOfDocuments': the_number_of_documents_added}
{'numberOfDocuments': the_number_of_documents_added}