I found your question while trying to see if I could create an index and mappings in one go. I ended up just creating a second request for creating mappings.
1 2 3 4 5 6 7 8 9 10 | String mappingJson = new String(ByteStreams.toByteArray(mappingFile.getInputStream())); boolean indexExists = client.execute(new IndicesExists.Builder(configuration.getIndex()).build()).isSucceeded(); if (indexExists) { logger.info("Updating elasticsearch type mapping."); client.execute(new PutMapping.Builder(configuration.getIndex(), configuration.getBaseType(), mappingJson).build()); } else { logger.info("Creating elasticsearch index and type mapping."); client.execute(new CreateIndex.Builder(configuration.getIndex()).build()); client.execute(new PutMapping.Builder(configuration.getIndex(), configuration.getBaseType(), mappingJson).build()); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.