align with es221

This commit is contained in:
Jörg Prante 2021-04-23 11:06:25 +02:00
parent e88e352ca5
commit 686e63f106
3 changed files with 21 additions and 11 deletions

View file

@ -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());

View file

@ -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<String, Object> mappings = JsonXContent.jsonXContent.createParser(indexDefinition.getMappings()).mapOrdered();

View file

@ -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