Search code examples
pythonibm-watsonwatson-discovery

Watson Discovery v2, count documents into a collection


I know that this might be trivial, but I need to find a simple way to count documents within a Watson Discovery Collection (v2).

Before moving to v2, this is what I used to do:

## Discovery v2
def collection_length(env, collection):
    total = 0
    for coll in collection:
        details = discovery.get_collection(env).get_result()
        total += details["document_counts"]["available"]
    return total

The same method into Watson SDK using Discovery v2 does not have any field for counting. I cannot query the whole collection and manually counts document since it takes a lot of time (timeout risk!).


Solution

  • package ibm_watson > 7 is needed.

    pip install --upgrade "ibm-watson>=7.0.0"