Joins in Elastic Query

Requirement : Objective is to calculate the metrics which is equivalent to SQL Query below.

SELECT COUNT(DISTINCT (required_column_name)) FROM table_1 A INNER JOIN table_1 B ON A.matching_column_name = B.matching_column_name WHERE A.distinguishing_column_name = 'distinguishing_value_A' AND B.distinguishing_column_name = 'distinguishing_value_B'.

Precisely an inner join on same table/index. (Example - http://www.sqlservertutorial.net/sql-server-basics/sql-server-self-join/). After which, I would like to calculate the proportion of the matching column between the two classes. For example, 30 percent of class A are present in class B.

Thanks for your time!

PS: While surfing related to inner join, I got suggestions to use Nested Query. But, I am not very sure about the usage for my requirement. If the same can be used, it would be helpful to have a sample query which I could use going forward.

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