Is there a better way to query for a index_instance total nodes, depth and document?

I am trying to get the total nodes, depth and document of a certain index_instance my approach was recursively call the cildren_url that I get from this endpoint:

/api/v4/index_instances/1/nodes/

My approach was working however it is not very efficient and takes a lot of time when performing due to sending an API request every time I use the children_url.

There is no method to get those numbers. Your approach works but as you noted it is not efficient and will get slower as the index grows.

These numbers are already obtained in the most efficient manner possible (1 query regardless of index levels) via the index methods get_descendants_document_count and get_descendants_count and get_level_count.

I’ve opened a ticket to expose these values via the API. Since the schema should remain backwards compatible, this can be included in a minor version.

The only concern would be if making these queries for the multiple levels that are shown in a single API result page impact the performance or the database memory usage too much.

1 Like