public synchronized CreateIndexResponse createIndex(String indexName, String settings, int shards) throws ElasticSearchException, IOException {
AdminLogger.log(this.getClass(), "createIndex",
"Trying to create index: " + indexName + " with shards: " + shards);
IndicesAdminClient iac = new ESClient().getClient().admin().indices();
if(shards <1){
try{
shards = Integer.parseInt(System.getProperty("es.index.number_of_shards"));
}catch(Exception e){}
}
if(shards <1){
try{
shards = Config.getIntProperty("es.index.number_of_shards");
}catch(Exception e){}
}
if(shards <0){
shards=1;
}
//default settings, if null
if(settings ==null){
settings = getDefaultIndexSettings(shards);
}
Map map = new ObjectMapper().readValue(settings, LinkedHashMap.class);
map.put("number_of_shards", shards);
// create actual index
CreateIndexRequestBuilder cirb = iac.prepareCreate(indexName).setSettings(map);
CreateIndexResponse createIndexResponse = cirb.execute().actionGet();
AdminLogger.log(this.getClass(), "createIndex",
"Index created: " + indexName + " with shards: " + shards);