marklogic_coder
marklogic_coder

Reputation: 1510

cts.estimate showing wrong document count

My requirement is get the count of total documents available in database.

cts.estimate(
  cts.trueQuery()
)

When I execute above query it is returning 1283265 document count but when I explore database from qconsole then document count is 1283262 so I am not sure about this document count mismatch.

Any help is appreciated.

Upvotes: 2

Views: 97

Answers (1)

Mads Hansen
Mads Hansen

Reputation: 66723

Is it possible that you have some URIs in the database that do not have documents?

The code backing the Query Console explore button only reports the estimated number of documents:

let $total-doc := xdmp:estimate(doc())

The default behavior for cts.estimate() is to search for any fragment.

Only one of "any", "document", "properties", or "locks" may be specified in the options parameter. If none of "any", "document", "properties", or "locks" are specified and there is a $query parameter, then the default is "document". If there is no $query parameter then the default is "any".

Run this query and verify what numbers are reported when explicit options are specified for estimates:

const estimate_default = cts.estimate(cts.trueQuery());
const estimate_any = cts.estimate(cts.trueQuery(), ["any"]);
const estimate_documents = cts.estimate(cts.trueQuery(), ["document"]);
const estimate_properties = cts.estimate(cts.trueQuery(), ["properties"]);
const estimate_locks = cts.estimate(cts.trueQuery(), ["locks"]);

[estimate_default, estimate_any, estimate_documents, estimate_properties, estimate_locks];

I would suspect that the difference in numbers is because of some URIs that do not have documents. It is possible, for instance, to have properties fragments for a URI and not have a document.

Upvotes: 2

Related Questions