title: How can I set a parent / child relationship using the Elastic Search Java API?
body: <p>I'm trying to create two documents, one build a child of the other, using the Elastic Search Java API.</p>
  
  <p>My code looks something like this:</p>
  
  <pre><code>public void createRecord(Road road, Car car) throws Exception{
    ObjectMapper objectMapper = new ObjectMapper();
  
    String roadJson = objectMapper.writeValueAsString(road);
    String carJson = objectMapper.writeValueAsString(car);
  
    Client client = TransportClient.builder().build().addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
  
    IndexResponse response = client.prepareIndex("myIndex", "roadType").setSource(roadJson).get();
  
    client.prepareIndex("myIndex", "carType").setParent(response.getId()).setSource(carJson).get();
  }
  </code></pre>
  
  <p>This code successfully creates a road document but when it goes to create a car document I get the error: </p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Can't specify parent if no parent
    field has been configured</p>
  </blockquote>
  
  <p>How can I properly create two Elastic documents that form a parent / child relationship with the ES Java API?</p>