Setting up indices (mappings, settings etc.)

Hello,

I am struggeling to set up my indices correctly. I have a mappings file and
a settings file that I would like to apply to my indices. Through trial and
error I figured out that the below code works for me.

However I am really not sure whether all steps that I take are necessary.
Also it seems that are various points it is advisable to givbe ES some time
to perform the last action (that is where I have the "Wait.forSeconds(5);"
line, which just waits for 5 seconds before proceeding.)

Could someone please comment on the below code, or point out to me how it
is done right?

Many thanks!
Peter

public void setUpIndex(String indexName){
try{
if
(CLIENT.admin().indices().exists(indicesExistsRequest(indexName)).actionGet().isExists()){

CLIENT.admin().indices().delete(deleteIndexRequest(indexName)).actionGet();
Wait.forSeconds(5);
System.out.println("Index '"+indexName+"' deleted.");
}

CLIENT.admin().indices().create(createIndexRequest(indexName)).actionGet();
Wait.forSeconds(5);
System.out.println("Index '"+indexName+"' (re)created.");

        Path settingPath = Paths.get(SETTINGS_FILE);
        System.out.println("Loading settings from "+settingPath);
        String settingString = new 

String(Files.readAllBytes(settingPath), StandardCharsets.UTF_8);

CLIENT.admin().indices().prepareClose(indexName).execute().actionGet();

CLIENT.admin().indices().prepareUpdateSettings(indexName).setSettings(settingString).execute().actionGet();
CLIENT.admin().indices().prepareOpen(indexName).execute().get();
System.out.println("Settings loaded from file and applied.");

        Path mappingPath = Paths.get(MAPPINGS_FILE);
        System.out.println("Loading mappings from "+mappingPath);
        String mappingString = new 

String(Files.readAllBytes(mappingPath), StandardCharsets.UTF_8);

CLIENT.admin().indices().preparePutMapping(indexName).setType("default").setSource(mappingString).execute().actionGet();
System.out.println("Post mapping set.");
}catch(Exception e){
System.out.println("Error! Cannot set up index
'"+indexName+"'.");
e.printStackTrace();
}
}

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/87bfe975-593d-4180-a77c-21165308f039%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi,

if anyone could comment on my code I would be very greatful. I'd like to
know whether my way to set up the index is as it is intended to be.

Thanks!

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9891deb3-aa0b-4efe-8838-ed8eed5fe354%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.