Inserting nested fields into Document using Java API? [Code Provided]

public static void createIndex() throws IOException 
{
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
        			        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));

final CreateIndexRequestBuilder createIndexRequestBuilder = client.admin().indices().prepareCreate("test");
final XContentBuilder mappingBuilder = jsonBuilder().startObject().startObject("testing")
        	                .startObject("properties").startObject("Tag").field("type", "nested").endObject().startObject("Address").field("type","nested").endObject()
        	                .endObject().endObject().endObject();
        	       
createIndexRequestBuilder.addMapping("testing", mappingBuilder);
createIndexRequestBuilder.execute().actionGet(); 

}
Above is how I am creating the index and mapping.

and inserting the document as:

IndexRequestBuilder indexRequestBuilder = client.prepareIndex("test", "testing", "1");
indexRequestBuilder.setSource(Data);
indexRequestBuilder.execute().actionGet();

where Data is a HashMap (String, String).

How do I make sure that Tag and Address are of nested type?
Is this the correct way to insert the document with nested type fields?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.