title: In Nest, how do I specify a child document's parent document while indexing?
body: <p><code>Product</code> and <code>Company</code> are in a many-to-one child-parent relationship:</p>
  
  <pre><code>[ElasticType(Name = "product", IdProperty = "ProductId")]
  internal class Product
  {
      public int ProductId { get; set; }
      public string Title { get; set; }
  }
  
  [ElasticType(Name = "company", IdProperty = "CompanyId")]
  public class Company
  {
     public int CompanyId { get; set; }
     public string CompanyName { get; set; }
  }
  </code></pre>
  
  <p>In the mapping of <code>Product</code>, I did:</p>
  
  <pre><code>Func&lt;PutMappingDescriptor&lt;Product&gt;, PutMappingDescriptor&lt;Product&gt;&gt; descriptor = m =&gt; m
                 .MapFromAttributes()
                 .AllField(a =&gt; a.Enabled(false))
                 .SetParent&lt;Company&gt;();
  </code></pre>
  
  <p>I created a parent and child:</p>
  
  <pre><code>var company = new Company {
      CompanyId = 1,
      CompanyName = "XYZ Company"
  };
  
  var p2 = new Product{
      ProductId = 2,
      Title = "ABC Product"
  };
  
  es.Index(company);
  </code></pre>
  
  <p>The problem is then, how do I index <code>p2</code>? With only the <code>Index</code> method, I can only do <code>es.Index(p2)</code>. But where do I indicate that <code>p2</code> should be indexed under the parent <code>company</code>?</p>
  
  <p><strong>Basically I wanted a NEST solution to <code>PUT /myindex/product/2?parent=1</code></strong>.</p>
  
  <p>The closest answer I found so far is in <a href="https://stackoverflow.com/a/23953742/1124270">https://stackoverflow.com/a/23953742/1124270</a>. But the answer uses bulk inserts like the following where you have a <code>.Parent</code> method in the chaining to specify the parent's ID:</p>
  
  <pre><code>var bulkResponse = _client.Bulk(b =&gt; b
              .Index&lt;Address&gt;(bd =&gt; bd.Object(new Address { Name = "Tel Aviv", Id = 1 }).Index("test"))
              .Index&lt;Person&gt;(bd =&gt; bd.Index("test").Object(new Person {Id = 5, Address = 1, Name = "Me"}).Parent(1)));
  </code></pre>