public void createMapping ( String indexName , String mappingName , ArrayList < XContentBuilder > mappingSource ) { IndicesExistsResponse existsResponse = this . client . admin ( ) . indices ( ) . prepareExists ( indexName ) . execute ( ) . actionGet ( ) ; //If the index does not exists, it will be created without options if ( ! existsResponse . isExists ( ) ) { if ( ! createSingleIndex ( indexName ) ) { throw new ElasticsearchException ( "Failed to create " + indexName + " index." ) ; } } BulkRequestBuilder bulkRequest = this . client . prepareBulk ( ) ; for ( int i = 0 ; i < mappingSource . size ( ) ; i ++ ) { int aux = i + 1 ; IndexRequestBuilder res = this . client . prepareIndex ( indexName , mappingName , String . valueOf ( aux ) ) . setSource ( mappingSource . get ( i ) ) ; bulkRequest . add ( res ) ; } bulkRequest . execute ( ) ; }
Create a mapping over an index