-
-
Save anonymous/56a1587a8384fc5ca364 to your computer and use it in GitHub Desktop.
creating index source
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void index() throws Exception { | |
IndexRequest indexRequest = createIndexRequest(index, type); | |
LOGGER.info("Going to create index for {}", indexRequest.id()); | |
final StopWatch stopWatch = new Slf4JStopWatch("ESIndexer.index...", | |
LOGGER); | |
client.index(indexRequest); | |
client.admin().indices().refresh(new RefreshRequest(index)); | |
stopWatch.stop(); | |
} | |
private IndexRequest createIndexRequest(String index, String type) throws Exception { | |
LOGGER.trace("Entering call {}", | |
Thread.currentThread().getStackTrace()[1].getMethodName()); | |
// get some mock doc in json format | |
String source = JSONVelocityGenerator.generateResource(); | |
String id = JSONVelocityGenerator.id(source); | |
if (id == null || id.isEmpty()) { | |
throw new Exception("Id cannot be null"); | |
} | |
IndexRequest indexRequest = new IndexRequest(); | |
indexRequest.index(index); | |
indexRequest.type(type); | |
indexRequest.source(source); | |
indexRequest.id(id); | |
LOGGER.trace("Exiting call {}", | |
Thread.currentThread().getStackTrace()[1].getMethodName()); | |
return indexRequest; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment