NOTE: You are looking at documentation for an older release. For the latest information, see the current release documentation.
Joining queries
editJoining queries
editPerforming full SQL-style joins in a distributed system like Elasticsearch is prohibitively expensive. Instead, Elasticsearch offers two forms of join which are designed to scale horizontally.
-
nestedquery -
Documents may contains fields of type
nested. These fields are used to index arrays of objects, where each object can be queried (with thenestedquery) as an independent document. -
has_childandhas_parentqueries -
A parent-child relationship can exist between two
document types within a single index. The
has_childquery returns parent documents whose child documents match the specified query, while thehas_parentquery returns child documents whose parent document matches the specified query.
Nested Query
editSee Nested Query
Has Child Query
editSee Has Child Query
When using the has_child query it is important to use the PreBuiltTransportClient instead of the regular client:
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new TransportAddress(new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 9300)));
Otherwise the parent-join module doesn’t get loaded and the has_child query can’t be used from the transport client.
Has Parent Query
editSee Has Parent
When using the has_parent query it is important to use the PreBuiltTransportClient instead of the regular client:
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new TransportAddress(new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 9300)));
Otherwise the parent-join module doesn’t get loaded and the has_parent query can’t be used from the transport client.