Onoxider
(Onoxider)
January 18, 2018, 3:29pm
1
Hello,
is there any way to put mapping with RestHighLevelClient?
I know that it's possible with TransportClient via this Doc page:
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-admin-indices.html
But as for RestHighLevelClient I haven't found any information.
Best regards
Добрый день!
Подскажите, пожалуйста, есть ли возможность задать маппинг через RestHighLevelClient?
ну или хотя бы через low level client.
с уважением,
val
(Val Crettaz)
January 18, 2018, 3:33pm
2
In one of the next versions 6.x, it looks like it will be possible to use the CreateIndex
API call which will allow to set a mapping at index creation time:
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.x/java-rest-high-create-index.html
dadoonet
(David Pilato)
January 18, 2018, 3:52pm
3
Yeah. And here is how I'm doing it in the mean time:
/**
* Create an index
* @param index index name
* @param ignoreErrors don't fail if the index already exists
* @param indexSettings index settings if any
* @throws IOException In case of error
*/
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 (!isNullOrEmpty(indexSettings)) {
entity = new StringEntity(indexSettings, ContentType.APPLICATION_JSON);
}
Response response = getLowLevelClient().performRequest("PUT", "/" + index, Collections.emptyMap(), entity);
logger.trace("create index response: {}", LowLevelClientJsonUtil.asMap(response));
} catch (ResponseException e) {
if (e.getResponse().getStatusLine().getStatusCode() == 400 &&
(e.getMessage().contains("index_already_exists_exception") || // ES 5.x
This file has been truncated. show original
2 Likes
Onoxider
(Onoxider)
January 19, 2018, 9:02am
4
I'm sorry, I forgot to mention that the version I'm using is 6.1, so it's better to get to 6.x since it has more features?
val
(Val Crettaz)
January 19, 2018, 9:17am
5
6.x is not released yet that was just a link to documentation of the next future release.
Onoxider
(Onoxider)
January 19, 2018, 10:39am
6
Yes, 6.1 is the current and it doesn't have CreateIndex API
By the way, for some reason gradle dependency is not working i.e. after ptting the following dependency no packages are being added to the project:
compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.2.0'
val
(Val Crettaz)
January 19, 2018, 10:42am
7
Normal since 6.2 is not released yet
You can inspire yourself from the code @dadoonet provided earlier, that should do the trick
Onoxider
(Onoxider)
January 19, 2018, 10:44am
8
Thank you, I'll look through it.
You are doing a workaround by getting lowlevelclient and performing basic http requests to put mapping, am I correct?
Onoxider
(Onoxider)
January 19, 2018, 10:46am
9
Yeah, apparently this is only way to do.
So, to sum up, there's no way in current stable version(6.1) to put mapping via High Level Client only, right?
val
(Val Crettaz)
January 19, 2018, 10:49am
10
Correct. As far as I know.
system
(system)
Closed
February 16, 2018, 10:50am
11
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.