dhavalk123
(Dhaval Kolapkar)
November 1, 2017, 10:50pm
1
Is there any way to create a custom index schema using a java high level client?
dadoonet
(David Pilato)
November 1, 2017, 11:05pm
2
You need to use the low level part for this for now. Here is how I'm doing that for now:
public void createIndex(String index, boolean ignoreErrors, String indexSettings) throws IOException {
logger.debug("create index [{}]", index);
logger.trace("index settings: [{}]", indexSettings);
try {
StringEntity entity = null;
if (!Strings.isNullOrEmpty(indexSettings)) {
entity = new StringEntity(indexSettings, ContentType.APPLICATION_JSON);
}
Response response = getLowLevelClient().performRequest("PUT", "/" + index, Collections.emptyMap(), entity);
logger.trace("create index response: {}", JsonUtil.asMap(response));
} catch (ResponseException e) {
if (e.getResponse().getStatusLine().getStatusCode() == 400 &&
(e.getMessage().contains("index_already_exists_exception") || // ES 5.x
e.getMessage().contains("resource_already_exists_exception") || // ES 6.x
e.getMessage().contains("IndexAlreadyExistsException") )) { // ES 1.x and 2.x
if (!ignoreErrors) {
throw new RuntimeException("index already exists");
}
logger.trace("index already exists. Ignoring error...");
return;
This file has been truncated. show original
The create index API is not yet part of the HL Client. See
system
(system)
Closed
November 29, 2017, 11:05pm
3
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.