# Count the number of documents that contain two values in one field

**URL:** <https://discuss.elastic.co/t/count-the-number-of-documents-that-contain-two-values-in-one-field/323140>\
**Category:** Elasticsearch\
**Created:** [January 13, 2023, 2:10pm UTC](https://discuss.elastic.co/t/count-the-number-of-documents-that-contain-two-values-in-one-field/323140 "2023-01-13T14:10:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve10](https://avatars.discourse-cdn.com/v4/letter/s/41988e/32.png) [@steve10](https://discuss.elastic.co/u/steve10)\
**Post date:** [January 13, 2023, 2:10pm UTC](https://discuss.elastic.co/t/count-the-number-of-documents-that-contain-two-values-in-one-field/323140/1 "2023-01-13T14:10:15Z")

</div>

Hi,

I have a number of documents like this in Elastic Search database:

```auto

Document 1:

{
“Id”: 6000,
“customerName”: GT,
“customerValue”: 10
}

Document 2:
{
“Id”: 6001,
“customerName”: MX,
“customerValue”: 10
}

Document 3:
{
“Id”: 6002,
“customerName”: MX,
“customerValue”: 13
}

Document 4:
{
“Id”: 6003,
“customerName”: GT,
“customerValue”: 22
}

Document 5:
{
“Id”: 6003,
“customerName”: MX,
“customerValue”: 22
}

```

I need to count the number of customerValue fields that that appear in two documents - with customer Name GT and MX. Basically, I want to count how many times customerValue is shared between customerName of GT and MX.  
So, from the documents above I would count 2 of customerValue entries - one shared between Document 1 and Document 2 and second shared between Document 4 and Document 5.  
How can I write a DSL query to do this?

---

<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 10, 2023, 2:11pm UTC](https://discuss.elastic.co/t/count-the-number-of-documents-that-contain-two-values-in-one-field/323140/2 "2023-02-10T14:11:12Z")

</div>

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