title: XContentBuilder Elasticsearch mapping for inner objects
body: <p>I am trying to create a mapping for documents of the following structure:</p>
  
  <pre><code>"name":"Peter"
  "id":"ABC123",  
  "values":{
      "a":3.0123,        
      "b":1234
  }
  </code></pre>
  
  <p>So the mapping should look like this:</p>
  
  <pre><code>{
   "properties":{"_all":{"enabled":"false"},
   "dynamic":"false",
   "_timestamp":{"enabled":true,"store":true},
   "properties": {
       "name":{"type":"string"},
       "id":{"type":"string"},
       "values": {
           "properties": {
                "a": {"type":"double"},
                "b":{"type":"double"}
            }
       }
     } 
    }
  }
  </code></pre>
  
  <p>In reality the amount of possible properties in "values" is quite big, let's say 50 possible properties I have to include there..</p>
  
  <p>I am currently generating the mapping json with the XContentBuilder, which works really fine for me. </p>
  
  <p>What I want to do is, encapsulating the inner part's mapping in "values" in a seperate builder, as it makes the process of mapping easier to maintain for me. Also I already have the inner properties' names in a list, which I'd  like to iterate.</p>
  
  <p>Thats my normal mapping code here.</p>
  
  <pre><code>XContentBuilder xbMapping = jsonBuilder()
              .startObject() // start root
                  .startObject(PROPERTIES)
                      .startObject("_all").field("enabled", "false").endObject()
                      .field("dynamic", "false")
                      .startObject("_timestamp").field("enabled", true).field("store", true).endObject()
                      .startObject(PROPERTIES)
                          .startObject("name").field("type", "string").endObject()
                          .startObject("id").field("type", "string").endObject()
                          .startObject("values")
                              .startObject(PROPERTIES)
                                   // INNER MAPPING HERE!!
                              .endObject()
                          .endObject()
                  .endObject()
              .endObject();
  </code></pre>
  
  <p>I'd like to avoid iterating in between those startObject and endObject and more like to do the complete mapping for the inner type somewhere else and just include that extra part there.</p>
  
  <p>I can't find a sophisticated way at the moment with XContentBuilder.</p>
  
  <p>Thanks for any hints</p>