I am (re)writing an index creation app in java and struggling a little bit.
The existing app uses the TransportClient and I want to move to the High Level Rest Client (using the low level Rest Client to set it up). I want to create a new index and to do this I am following the migration documentation.
Starting with the sample code along these lines
Settings indexSettings = Settings.builder()
.put("index.number_of_shards", 1)
.put("index.number_of_replicas", 0)
.put("path.data", "NewDevCluster") //THIS SETTING FAILS!
.build();
String payload = XContentFactory.jsonBuilder()
.startObject()
.startObject("settings")
.value(indexSettings)
.endObject()
.startObject("mappings")
.startObject("doc")
.startObject("properties")
.startObject("time")
.field("type", "date")
.endObject()
.endObject()
.endObject()
.endObject()
.endObject().string();
HttpEntity entityCreate = new NStringEntity(payload, ContentType.APPLICATION_JSON);
//CREATE INDEX
Response response = restClient.performRequest("PUT", "newIndex", emptyMap(), entityCreate);
So...
This does the basics that I want (although I haven't figured out how to point it to a new cluster yet - in the long term I'm not sure whether I want to do this anyway maybe a new index or an alias will suffice ...)
However I have a general settings file (along these lines)
{
"index" : {
"analysis" : {
"char_filter" : {
"gref_mapping" : {
"type" : "mapping",
"mappings" : ["/=>E"]
}
},
"analyzer" : {
"gref_char_filter" : {
"tokenizer" : "standard",
"char_filter" : ["gref_mapping"]
}
}
}
}
}
which are being loaded into the transport client like
> String settingsSource=getSourceFromMappingFile("settings.json");
CreateIndexResponse resp = client.admin().indices().create(new CreateIndexRequest(INDEX_NAME).settings(settingsSource)).actionGet();
and a set of large mapping files which are loaded like this
client.admin(). indices(). preparePutMapping(indexName). setSource(getSourceFromMappingFile(mappingFile)). setType(indexType). execute(). actionGet();
I'm struggling to move towards loading these using the restclients. Tbh I haven't tried very hard with the mapping files yet, and I can see how I could load them in a very long winded way but presumably there is a better way than creating an enourmous mapping section by loading 30 - 40 json documents into a XContentFactory.jsonBuilder ?) and I'm assuming there must be a way to load from file ?
Anyway what I'm asking is
- Is it definitely possible to load the settings and mapping files ?
- Can anyone point me in the right direction as to how I should do this