# Want to get distinct record across 2 fields

**URL:** <https://discuss.elastic.co/t/want-to-get-distinct-record-across-2-fields/234740>\
**Category:** Elasticsearch\
**Created:** [May 28, 2020, 12:27pm UTC](https://discuss.elastic.co/t/want-to-get-distinct-record-across-2-fields/234740 "2020-05-28T12:27:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khirod\_Panda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khirod_panda/32/47010_2.png) [@Khirod\_Panda](https://discuss.elastic.co/u/Khirod_Panda)\
**Post date:** [May 28, 2020, 12:27pm UTC](https://discuss.elastic.co/t/want-to-get-distinct-record-across-2-fields/234740/1 "2020-05-28T12:27:16Z")

</div>

I have an index where data may be duplicating . but in those duplicating data set. i have 2 fields that does not change . Now I want to get count of distinct records

Ex:-  
cid='AE123456XYZ',  
opname ='getData'  
isError=1  
error='blah'

in the above cid, opname ,isError will repeat across the duplicate data set. I want to find distinct counts based on those 2 (cid & opname) combination. Is that possible ?

---

<div class="post-metadata">

**Author:** ![ssouris](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ssouris/32/68657_2.png) [@ssouris](https://discuss.elastic.co/u/ssouris)\
**Post date:** [May 28, 2020, 3:54pm UTC](https://discuss.elastic.co/t/want-to-get-distinct-record-across-2-fields/234740/2 "2020-05-28T15:54:08Z")

</div>

You could use something like a terms aggregation and then a sub aggregation on cardinality.  
e.g.

> <https://gist.github.com/ssouris/c248115e9ac4bc11577cfcdea2cee70e>

Also, you could pre-index those fields into one and just do a terms aggregation on that new field.

I hope this helps.

---

<div class="post-metadata">

**Author:** ![Khirod\_Panda](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/khirod_panda/32/47010_2.png) [@Khirod\_Panda](https://discuss.elastic.co/u/Khirod_Panda)\
**Post date:** [May 30, 2020, 3:11am UTC](https://discuss.elastic.co/t/want-to-get-distinct-record-across-2-fields/234740/3 "2020-05-30T03:11:00Z")

</div>

Thanks . let me try this out .

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 27, 2020, 3:11am UTC](https://discuss.elastic.co/t/want-to-get-distinct-record-across-2-fields/234740/4 "2020-06-27T03:11:03Z")

</div>

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