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

Hi,

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


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?

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