has-parent-query.asciidoc 1.0 KB

1234567891011121314151617181920212223
  1. [[java-query-dsl-has-parent-query]]
  2. ==== Has Parent Query
  3. See {ref}/query-dsl-has-parent-query.html[Has Parent]
  4. When using the `has_parent` query it is important to use the `PreBuiltTransportClient` instead of the regular client:
  5. [source,java]
  6. --------------------------------------------------
  7. Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
  8. TransportClient client = new PreBuiltTransportClient(settings);
  9. client.addTransportAddress(new TransportAddress(new InetSocketAddress(InetAddresses.forString("127.0.0.1"), 9300)));
  10. --------------------------------------------------
  11. Otherwise the parent-join module doesn't get loaded and the `has_parent` query can't be used from the transport client.
  12. ["source","java",subs="attributes,callouts,macros"]
  13. --------------------------------------------------
  14. include-tagged::{query-dsl-test}[has_parent]
  15. --------------------------------------------------
  16. <1> parent type to query against
  17. <2> query
  18. <3> whether the score from the parent hit should propagate to the child hit