# Get doc count where two columns value are same

**URL:** <https://discuss.elastic.co/t/get-doc-count-where-two-columns-value-are-same/165035>\
**Category:** Elasticsearch\
**Created:** [January 21, 2019, 11:21am UTC](https://discuss.elastic.co/t/get-doc-count-where-two-columns-value-are-same/165035 "2019-01-21T11:21:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![examin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/examin/32/70688_2.png) [@examin](https://discuss.elastic.co/u/examin)\
**Post date:** [January 21, 2019, 11:21am UTC](https://discuss.elastic.co/t/get-doc-count-where-two-columns-value-are-same/165035/1 "2019-01-21T11:21:30Z")

</div>

How to get count of search , where year=2019 and "start\_date"="end\_date". Please guide me how can this be done in java.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 21, 2019, 11:57am UTC](https://discuss.elastic.co/t/get-doc-count-where-two-columns-value-are-same/165035/2 "2019-01-21T11:57:45Z")

</div>

You can may be use a painless script to solve the field equality part but that will be slow.

If this is something you intend to do a lot of time, I'd recommend computing at index time something like a duration field for example.

Then it will be easy to find documents in 2019 where duration is 0.

---

<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:** [February 18, 2019, 11:57am UTC](https://discuss.elastic.co/t/get-doc-count-where-two-columns-value-are-same/165035/3 "2019-02-18T11:57:48Z")

</div>

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