From 686e63f1064a6d6cad4edb38c7ca2be1accfa491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Fri, 23 Apr 2021 11:06:25 +0200 Subject: [PATCH] align with es221 --- .../xbib/elx/common/AbstractBasicClient.java | 8 +++---- .../xbib/elx/common/AbstractBulkClient.java | 22 ++++++++++++++----- gradle.properties | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java index 0fb30dd..0135338 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractBasicClient.java @@ -205,16 +205,16 @@ public abstract class AbstractBasicClient implements BasicClient { protected abstract void closeClient(Settings settings) throws IOException; - protected void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) throws IOException { + protected void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) { ensureClientIsPresent(); if (index == null) { - throw new IOException("no index name given"); + throw new IllegalArgumentException("no index name given"); } if (key == null) { - throw new IOException("no key given"); + throw new IllegalArgumentException("no key given"); } if (value == null) { - throw new IOException("no value given"); + throw new IllegalArgumentException("no value given"); } Settings.Builder updateSettingsBuilder = Settings.builder(); updateSettingsBuilder.put(key, value.toString()); diff --git a/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java b/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java index 3fcd849..c630ce4 100644 --- a/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java +++ b/elx-common/src/main/java/org/xbib/elx/common/AbstractBulkClient.java @@ -13,7 +13,6 @@ import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; import org.elasticsearch.action.delete.DeleteRequest; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.update.UpdateRequest; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; @@ -92,18 +91,29 @@ public abstract class AbstractBulkClient extends AbstractBasicClient implements new CreateIndexRequestBuilder(client, CreateIndexAction.INSTANCE) .setIndex(index); if (indexDefinition.getSettings() != null) { - indexDefinition.setSettings(Strings.toString(Settings.builder() + Settings settings = Settings.builder() .loadFromSource(indexDefinition.getSettings()) .put("index.number_of_shards", indexDefinition.getShardCount()) .put("index.number_of_replicas", 0) // always 0 - .build())); + .build(); + try { + createIndexRequestBuilder.setSettings(JsonXContent.contentBuilder() + .map(settings.getAsStructuredMap()).string()); + } catch (IOException e) { + logger.warn(e.getMessage(), e); + } } else { - indexDefinition.setSettings(Strings.toString(Settings.builder() + Settings settings = Settings.builder() .put("index.number_of_shards", indexDefinition.getShardCount()) .put("index.number_of_replicas", 0) // always 0 - .build())); + .build(); + try { + createIndexRequestBuilder.setSettings(JsonXContent.contentBuilder() + .map(settings.getAsStructuredMap()).string()); + } catch (IOException e) { + logger.warn(e.getMessage(), e); + } } - createIndexRequestBuilder.setSettings(indexDefinition.getSettings()); if (indexDefinition.getMappings() != null) { try { Map mappings = JsonXContent.jsonXContent.createParser(indexDefinition.getMappings()).mapOrdered(); diff --git a/gradle.properties b/gradle.properties index 2dd2a34..178e078 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = org.xbib name = elx -version = 2.2.1.45 +version = 2.2.1.46 gradle.wrapper.version = 6.6.1 xbib-metrics.version = 2.1.0