private boolean createIndex ( String index , Map < String , Object > defaultSettings ) { IndicesExistsResponse res = client . admin ( ) . indices ( ) . prepareExists ( index ) . execute ( ) . actionGet ( ) ; boolean created = false ; if ( ! res . isExists ( ) ) { CreateIndexRequestBuilder req = client . admin ( ) . indices ( ) . prepareCreate ( index ) ; req . setSettings ( defaultSettings ) ; created = req . execute ( ) . actionGet ( ) . isAcknowledged ( ) ; if ( ! created ) { throw new RuntimeException ( "Could not create index [" + index + "]" ) ; } } return created ; }
Check if index is created . if not it will created it