Count how many items appear once and only once

I have a set of documents with a user ID field which may appear once or many times accross the set of documents.

I know i can count unique users. But i would like to know how many users appear in my document set once and only once. (and also how many appear more than once).

If anyone has a solution would appreciate your help!
Thanks

To find users that appear more than once, you could use a terms agg with the min_doc_count set to 2 in the Advanced section of the aggregation config. Like this:

Finding users that appear exactly once is harder. You could simply sort ascending with a min_doc_count of 1, but that operation is deprecated because it results in document counts with unbounded errors. I can't think of a good way to find users that appear exactly once with the given schema.

1 Like

Thanks Bargs! Works great.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.