|
|
@ -41,11 +41,6 @@ import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
|
|
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
|
|
|
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
|
|
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|
|
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
|
import org.elasticsearch.common.unit.TimeValue;
|
|
|
|
|
|
|
|
import org.elasticsearch.common.xcontent.ToXContent;
|
|
|
|
|
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
|
|
|
|
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
|
|
|
|
|
|
|
import org.elasticsearch.common.xcontent.yaml.YamlXContent;
|
|
|
|
|
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
|
import org.elasticsearch.index.query.QueryBuilder;
|
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
|
import org.elasticsearch.index.query.QueryBuilders;
|
|
|
|
import org.elasticsearch.search.SearchHit;
|
|
|
|
import org.elasticsearch.search.SearchHit;
|
|
|
@ -57,18 +52,10 @@ import org.xbib.elx.api.AdminClient;
|
|
|
|
import org.xbib.elx.api.IndexAliasAdder;
|
|
|
|
import org.xbib.elx.api.IndexAliasAdder;
|
|
|
|
import org.xbib.elx.api.IndexDefinition;
|
|
|
|
import org.xbib.elx.api.IndexDefinition;
|
|
|
|
import org.xbib.elx.api.IndexPruneResult;
|
|
|
|
import org.xbib.elx.api.IndexPruneResult;
|
|
|
|
import org.xbib.elx.api.IndexRetention;
|
|
|
|
|
|
|
|
import org.xbib.elx.api.IndexShiftResult;
|
|
|
|
import org.xbib.elx.api.IndexShiftResult;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
import java.nio.charset.MalformedInputException;
|
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
|
|
|
import java.time.ZoneId;
|
|
|
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
@ -94,30 +81,28 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
|
|
|
|
|
|
|
|
private static final Logger logger = LogManager.getLogger(AbstractAdminClient.class.getName());
|
|
|
|
private static final Logger logger = LogManager.getLogger(AbstractAdminClient.class.getName());
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* The one and only index type name used in the extended client.
|
|
|
|
|
|
|
|
* Notr that all Elasticsearch version < 6.2.0 do not allow a prepending "_".
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
private static final String TYPE_NAME = "doc";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Map<String, ?> getMapping(String index) throws IOException {
|
|
|
|
public Map<String, ?> getMapping(IndexDefinition indexDefinition) throws IOException {
|
|
|
|
|
|
|
|
if (!ensureIndexDefinition(indexDefinition)) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
GetMappingsRequestBuilder getMappingsRequestBuilder = new GetMappingsRequestBuilder(client, GetMappingsAction.INSTANCE)
|
|
|
|
GetMappingsRequestBuilder getMappingsRequestBuilder = new GetMappingsRequestBuilder(client, GetMappingsAction.INSTANCE)
|
|
|
|
.setIndices(index)
|
|
|
|
.setIndices(indexDefinition.getFullIndexName())
|
|
|
|
.setTypes(TYPE_NAME);
|
|
|
|
.setTypes(indexDefinition.getType());
|
|
|
|
GetMappingsResponse getMappingsResponse = getMappingsRequestBuilder.execute().actionGet();
|
|
|
|
GetMappingsResponse getMappingsResponse = getMappingsRequestBuilder.execute().actionGet();
|
|
|
|
logger.info("get mappings response = {}", getMappingsResponse.getMappings().get(index).get(TYPE_NAME).getSourceAsMap());
|
|
|
|
return getMappingsResponse.getMappings()
|
|
|
|
return getMappingsResponse.getMappings().get(index).get(TYPE_NAME).getSourceAsMap();
|
|
|
|
.get(indexDefinition.getFullIndexName())
|
|
|
|
|
|
|
|
.get(indexDefinition.getType())
|
|
|
|
|
|
|
|
.getSourceAsMap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public AdminClient deleteIndex(IndexDefinition indexDefinition) {
|
|
|
|
public AdminClient deleteIndex(IndexDefinition indexDefinition) {
|
|
|
|
return deleteIndex(indexDefinition.getFullIndexName());
|
|
|
|
if (!ensureIndexDefinition(indexDefinition)) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public AdminClient deleteIndex(String index) {
|
|
|
|
|
|
|
|
ensureClientIsPresent();
|
|
|
|
ensureClientIsPresent();
|
|
|
|
|
|
|
|
String index = indexDefinition.getFullIndexName();
|
|
|
|
if (index == null) {
|
|
|
|
if (index == null) {
|
|
|
|
logger.warn("no index name given to delete index");
|
|
|
|
logger.warn("no index name given to delete index");
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
@ -130,27 +115,27 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public AdminClient updateReplicaLevel(IndexDefinition indexDefinition, int level) throws IOException {
|
|
|
|
public AdminClient updateReplicaLevel(IndexDefinition indexDefinition, int level) throws IOException {
|
|
|
|
return updateReplicaLevel(indexDefinition.getFullIndexName(), level,
|
|
|
|
if (!ensureIndexDefinition(indexDefinition)) {
|
|
|
|
indexDefinition.getMaxWaitTime(), indexDefinition.getMaxWaitTimeUnit());
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public AdminClient updateReplicaLevel(String index, int level, long maxWaitTime, TimeUnit timeUnit) throws IOException {
|
|
|
|
|
|
|
|
if (level < 1) {
|
|
|
|
if (level < 1) {
|
|
|
|
logger.warn("invalid replica level");
|
|
|
|
logger.warn("invalid replica level");
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
String index = indexDefinition.getFullIndexName();
|
|
|
|
|
|
|
|
long maxWaitTime = indexDefinition.getMaxWaitTime();
|
|
|
|
|
|
|
|
TimeUnit timeUnit = indexDefinition.getMaxWaitTimeUnit();
|
|
|
|
updateIndexSetting(index, "number_of_replicas", level, maxWaitTime, timeUnit);
|
|
|
|
updateIndexSetting(index, "number_of_replicas", level, maxWaitTime, timeUnit);
|
|
|
|
return this;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getReplicaLevel(IndexDefinition indexDefinition) {
|
|
|
|
public int getReplicaLevel(IndexDefinition indexDefinition) {
|
|
|
|
return getReplicaLevel(indexDefinition.getFullIndexName());
|
|
|
|
if (!ensureIndexDefinition(indexDefinition)) {
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureClientIsPresent();
|
|
|
|
@Override
|
|
|
|
String index = indexDefinition.getFullIndexName();
|
|
|
|
public int getReplicaLevel(String index) {
|
|
|
|
|
|
|
|
GetSettingsRequest request = new GetSettingsRequest().indices(index);
|
|
|
|
GetSettingsRequest request = new GetSettingsRequest().indices(index);
|
|
|
|
GetSettingsResponse response = client.execute(GetSettingsAction.INSTANCE, request).actionGet();
|
|
|
|
GetSettingsResponse response = client.execute(GetSettingsAction.INSTANCE, request).actionGet();
|
|
|
|
int replica = -1;
|
|
|
|
int replica = -1;
|
|
|
@ -165,10 +150,10 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String resolveMostRecentIndex(String alias) {
|
|
|
|
public String resolveMostRecentIndex(String alias) {
|
|
|
|
ensureClientIsPresent();
|
|
|
|
|
|
|
|
if (alias == null) {
|
|
|
|
if (alias == null) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureClientIsPresent();
|
|
|
|
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().aliases(alias);
|
|
|
|
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().aliases(alias);
|
|
|
|
GetAliasesResponse getAliasesResponse = client.execute(GetAliasesAction.INSTANCE, getAliasesRequest).actionGet();
|
|
|
|
GetAliasesResponse getAliasesResponse = client.execute(GetAliasesAction.INSTANCE, getAliasesRequest).actionGet();
|
|
|
|
Pattern pattern = Pattern.compile("^(.*?)(\\d+)$");
|
|
|
|
Pattern pattern = Pattern.compile("^(.*?)(\\d+)$");
|
|
|
@ -187,6 +172,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
if (index == null) {
|
|
|
|
if (index == null) {
|
|
|
|
return Collections.emptyMap();
|
|
|
|
return Collections.emptyMap();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureClientIsPresent();
|
|
|
|
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index);
|
|
|
|
GetAliasesRequest getAliasesRequest = new GetAliasesRequest().indices(index);
|
|
|
|
return getFilters(client.execute(GetAliasesAction.INSTANCE, getAliasesRequest).actionGet());
|
|
|
|
return getFilters(client.execute(GetAliasesAction.INSTANCE, getAliasesRequest).actionGet());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -210,12 +196,6 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
return aliasOrIndex != null ? aliasOrIndex.getIndices().stream().map(IndexMetaData::getIndex).collect(Collectors.toList()) : Collections.emptyList();
|
|
|
|
return aliasOrIndex != null ? aliasOrIndex.getIndices().stream().map(IndexMetaData::getIndex).collect(Collectors.toList()) : Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public IndexShiftResult shiftIndex(IndexDefinition indexDefinition,
|
|
|
|
|
|
|
|
List<String> additionalAliases) {
|
|
|
|
|
|
|
|
return shiftIndex(indexDefinition, additionalAliases, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public IndexShiftResult shiftIndex(IndexDefinition indexDefinition,
|
|
|
|
public IndexShiftResult shiftIndex(IndexDefinition indexDefinition,
|
|
|
|
List<String> additionalAliases,
|
|
|
|
List<String> additionalAliases,
|
|
|
@ -223,6 +203,9 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
if (additionalAliases == null) {
|
|
|
|
if (additionalAliases == null) {
|
|
|
|
return new EmptyIndexShiftResult();
|
|
|
|
return new EmptyIndexShiftResult();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ensureIndexDefinition(indexDefinition)) {
|
|
|
|
|
|
|
|
return new EmptyIndexShiftResult();
|
|
|
|
|
|
|
|
}
|
|
|
|
if (indexDefinition.isShiftEnabled()) {
|
|
|
|
if (indexDefinition.isShiftEnabled()) {
|
|
|
|
return shiftIndex(indexDefinition.getIndex(),
|
|
|
|
return shiftIndex(indexDefinition.getIndex(),
|
|
|
|
indexDefinition.getFullIndexName(), additionalAliases.stream()
|
|
|
|
indexDefinition.getFullIndexName(), additionalAliases.stream()
|
|
|
@ -380,7 +363,10 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Long mostRecentDocument(String index, String timestampfieldname) {
|
|
|
|
public Long mostRecentDocument(IndexDefinition indexDefinition, String timestampfieldname) {
|
|
|
|
|
|
|
|
if (!ensureIndexDefinition(indexDefinition)) {
|
|
|
|
|
|
|
|
return -1L;
|
|
|
|
|
|
|
|
}
|
|
|
|
ensureClientIsPresent();
|
|
|
|
ensureClientIsPresent();
|
|
|
|
SortBuilder sort = SortBuilders.fieldSort(timestampfieldname).order(SortOrder.DESC);
|
|
|
|
SortBuilder sort = SortBuilders.fieldSort(timestampfieldname).order(SortOrder.DESC);
|
|
|
|
SearchSourceBuilder builder = new SearchSourceBuilder();
|
|
|
|
SearchSourceBuilder builder = new SearchSourceBuilder();
|
|
|
@ -388,7 +374,7 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
builder.field(timestampfieldname);
|
|
|
|
builder.field(timestampfieldname);
|
|
|
|
builder.size(1);
|
|
|
|
builder.size(1);
|
|
|
|
SearchRequest searchRequest = new SearchRequest();
|
|
|
|
SearchRequest searchRequest = new SearchRequest();
|
|
|
|
searchRequest.indices(index);
|
|
|
|
searchRequest.indices(indexDefinition.getFullIndexName());
|
|
|
|
searchRequest.source(builder);
|
|
|
|
searchRequest.source(builder);
|
|
|
|
SearchResponse searchResponse = client.execute(SearchAction.INSTANCE, searchRequest).actionGet();
|
|
|
|
SearchResponse searchResponse = client.execute(SearchAction.INSTANCE, searchRequest).actionGet();
|
|
|
|
if (searchResponse.getHits().getHits().length == 1) {
|
|
|
|
if (searchResponse.getHits().getHits().length == 1) {
|
|
|
@ -399,25 +385,25 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
return 0L;
|
|
|
|
return 0L;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
// almost impossible
|
|
|
|
|
|
|
|
return -1L;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean forceMerge(IndexDefinition indexDefinition) {
|
|
|
|
public boolean forceMerge(IndexDefinition indexDefinition) {
|
|
|
|
if (indexDefinition.isForceMergeEnabled()) {
|
|
|
|
if (!ensureIndexDefinition(indexDefinition)) {
|
|
|
|
return forceMerge(indexDefinition.getFullIndexName(), indexDefinition.getMaxWaitTime(),
|
|
|
|
return false;
|
|
|
|
indexDefinition.getMaxWaitTimeUnit());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!indexDefinition.isForceMergeEnabled()) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureClientIsPresent();
|
|
|
|
@Override
|
|
|
|
String index = indexDefinition.getFullIndexName();
|
|
|
|
public boolean forceMerge(String index, long maxWaitTime, TimeUnit timeUnit) {
|
|
|
|
|
|
|
|
TimeValue timeout = toTimeValue(maxWaitTime, timeUnit);
|
|
|
|
|
|
|
|
ForceMergeRequest forceMergeRequest = new ForceMergeRequest();
|
|
|
|
ForceMergeRequest forceMergeRequest = new ForceMergeRequest();
|
|
|
|
forceMergeRequest.indices(index);
|
|
|
|
forceMergeRequest.indices(index);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
client.execute(ForceMergeAction.INSTANCE, forceMergeRequest).get(timeout.getMillis(), TimeUnit.MILLISECONDS);
|
|
|
|
client.execute(ForceMergeAction.INSTANCE, forceMergeRequest)
|
|
|
|
|
|
|
|
.get(indexDefinition.getMaxWaitTime(), indexDefinition.getMaxWaitTimeUnit());
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
} catch (TimeoutException e) {
|
|
|
|
} catch (TimeoutException e) {
|
|
|
|
logger.error("timeout");
|
|
|
|
logger.error("timeout");
|
|
|
@ -430,45 +416,12 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public IndexDefinition buildIndexDefinitionFromSettings(String index, Settings settings)
|
|
|
|
|
|
|
|
throws IOException {
|
|
|
|
|
|
|
|
boolean isEnabled = settings.getAsBoolean("enabled", false);
|
|
|
|
|
|
|
|
String indexName = settings.get("name", index);
|
|
|
|
|
|
|
|
String dateTimePatternStr = settings.get("dateTimePattern", "^(.*?)(\\\\d+)$");
|
|
|
|
|
|
|
|
Pattern dateTimePattern = Pattern.compile(dateTimePatternStr);
|
|
|
|
|
|
|
|
String dateTimeFormat = settings.get("dateTimeFormat", "yyyyMMdd");
|
|
|
|
|
|
|
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateTimeFormat)
|
|
|
|
|
|
|
|
.withZone(ZoneId.systemDefault());
|
|
|
|
|
|
|
|
String fullName = indexName + dateTimeFormatter.format(LocalDate.now());
|
|
|
|
|
|
|
|
String fullIndexName = resolveAlias(fullName).stream().findFirst().orElse(fullName);
|
|
|
|
|
|
|
|
IndexRetention indexRetention = new DefaultIndexRetention()
|
|
|
|
|
|
|
|
.setMinToKeep(settings.getAsInt("retention.mintokeep", 0))
|
|
|
|
|
|
|
|
.setDelta(settings.getAsInt("retention.delta", 0));
|
|
|
|
|
|
|
|
return new DefaultIndexDefinition()
|
|
|
|
|
|
|
|
.setEnabled(isEnabled)
|
|
|
|
|
|
|
|
.setIndex(indexName)
|
|
|
|
|
|
|
|
.setFullIndexName(fullIndexName)
|
|
|
|
|
|
|
|
.setSettings(findSettingsFrom(settings.get("settings")))
|
|
|
|
|
|
|
|
.setMappings(findMappingsFrom(settings.get("mapping")))
|
|
|
|
|
|
|
|
.setDateTimeFormatter(dateTimeFormatter)
|
|
|
|
|
|
|
|
.setDateTimePattern(dateTimePattern)
|
|
|
|
|
|
|
|
.setIgnoreErrors(settings.getAsBoolean("skiperrors", false))
|
|
|
|
|
|
|
|
.setShift(settings.getAsBoolean("shift", true))
|
|
|
|
|
|
|
|
.setPrune(settings.getAsBoolean("prune", true))
|
|
|
|
|
|
|
|
.setReplicaLevel(settings.getAsInt("replica", 0))
|
|
|
|
|
|
|
|
.setMaxWaitTime(settings.getAsLong("timeout", 30L), TimeUnit.SECONDS)
|
|
|
|
|
|
|
|
.setRetention(indexRetention)
|
|
|
|
|
|
|
|
.setStartRefreshInterval(settings.getAsLong("bulk.startrefreshinterval", -1L))
|
|
|
|
|
|
|
|
.setStopRefreshInterval(settings.getAsLong("bulk.stoprefreshinterval", -1L));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) throws IOException {
|
|
|
|
public void updateIndexSetting(String index, String key, Object value, long timeout, TimeUnit timeUnit) throws IOException {
|
|
|
|
ensureClientIsPresent();
|
|
|
|
|
|
|
|
if (index == null) {
|
|
|
|
if (index == null) {
|
|
|
|
throw new IOException("no index name given");
|
|
|
|
throw new IOException("no index name given");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ensureClientIsPresent();
|
|
|
|
Settings.Builder updateSettingsBuilder = Settings.builder();
|
|
|
|
Settings.Builder updateSettingsBuilder = Settings.builder();
|
|
|
|
updateSettingsBuilder.put(key, value.toString());
|
|
|
|
updateSettingsBuilder.put(key, value.toString());
|
|
|
|
UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(index)
|
|
|
|
UpdateSettingsRequest updateSettingsRequest = new UpdateSettingsRequest(index)
|
|
|
@ -477,9 +430,12 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void checkMapping(String index) {
|
|
|
|
public void checkMapping(IndexDefinition indexDefinition) {
|
|
|
|
|
|
|
|
if (!ensureIndexDefinition(indexDefinition)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
ensureClientIsPresent();
|
|
|
|
ensureClientIsPresent();
|
|
|
|
GetMappingsRequest getMappingsRequest = new GetMappingsRequest().indices(index);
|
|
|
|
GetMappingsRequest getMappingsRequest = new GetMappingsRequest().indices(indexDefinition.getFullIndexName());
|
|
|
|
GetMappingsResponse getMappingsResponse = client.execute(GetMappingsAction.INSTANCE, getMappingsRequest).actionGet();
|
|
|
|
GetMappingsResponse getMappingsResponse = client.execute(GetMappingsAction.INSTANCE, getMappingsRequest).actionGet();
|
|
|
|
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> map = getMappingsResponse.getMappings();
|
|
|
|
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> map = getMappingsResponse.getMappings();
|
|
|
|
map.keys().forEach((Consumer<ObjectCursor<String>>) stringObjectCursor -> {
|
|
|
|
map.keys().forEach((Consumer<ObjectCursor<String>>) stringObjectCursor -> {
|
|
|
@ -487,54 +443,11 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
for (ObjectObjectCursor<String, MappingMetaData> cursor : mappings) {
|
|
|
|
for (ObjectObjectCursor<String, MappingMetaData> cursor : mappings) {
|
|
|
|
String mappingName = cursor.key;
|
|
|
|
String mappingName = cursor.key;
|
|
|
|
MappingMetaData mappingMetaData = cursor.value;
|
|
|
|
MappingMetaData mappingMetaData = cursor.value;
|
|
|
|
checkMapping(index, mappingName, mappingMetaData);
|
|
|
|
checkMapping(indexDefinition.getFullIndexName(), mappingName, mappingMetaData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static String findSettingsFrom(String string) throws IOException {
|
|
|
|
|
|
|
|
if (string == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
URL url = new URL(string);
|
|
|
|
|
|
|
|
try (InputStream inputStream = url.openStream()) {
|
|
|
|
|
|
|
|
Settings settings = Settings.builder().loadFromStream(string, inputStream).build();
|
|
|
|
|
|
|
|
XContentBuilder builder = JsonXContent.contentBuilder();
|
|
|
|
|
|
|
|
settings.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
|
|
|
|
|
|
|
return builder.string();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
|
|
|
|
return string;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String findMappingsFrom(String string) throws IOException {
|
|
|
|
|
|
|
|
if (string == null) {
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
URL url = new URL(string);
|
|
|
|
|
|
|
|
try (InputStream inputStream = url.openStream()) {
|
|
|
|
|
|
|
|
if (string.endsWith(".json")) {
|
|
|
|
|
|
|
|
Map<String, ?> mappings = JsonXContent.jsonXContent.createParser(inputStream).mapOrdered();
|
|
|
|
|
|
|
|
XContentBuilder builder = JsonXContent.contentBuilder();
|
|
|
|
|
|
|
|
builder.startObject().map(mappings).endObject();
|
|
|
|
|
|
|
|
return builder.string();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string.endsWith(".yml") || string.endsWith(".yaml")) {
|
|
|
|
|
|
|
|
Map<String, ?> mappings = YamlXContent.yamlXContent.createParser(inputStream).mapOrdered();
|
|
|
|
|
|
|
|
XContentBuilder builder = JsonXContent.contentBuilder();
|
|
|
|
|
|
|
|
builder.startObject().map(mappings).endObject();
|
|
|
|
|
|
|
|
return builder.string();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return string;
|
|
|
|
|
|
|
|
} catch (MalformedInputException e) {
|
|
|
|
|
|
|
|
return string;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<String, String> getFilters(GetAliasesResponse getAliasesResponse) {
|
|
|
|
private Map<String, String> getFilters(GetAliasesResponse getAliasesResponse) {
|
|
|
|
Map<String, String> result = new HashMap<>();
|
|
|
|
Map<String, String> result = new HashMap<>();
|
|
|
|
for (ObjectObjectCursor<String, List<AliasMetaData>> object : getAliasesResponse.getAliases()) {
|
|
|
|
for (ObjectObjectCursor<String, List<AliasMetaData>> object : getAliasesResponse.getAliases()) {
|
|
|
@ -654,7 +567,6 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static class EmptyIndexShiftResult implements IndexShiftResult {
|
|
|
|
private static class EmptyIndexShiftResult implements IndexShiftResult {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -774,5 +686,4 @@ public abstract class AbstractAdminClient extends AbstractBasicClient implements
|
|
|
|
return "EMPTY PRUNE";
|
|
|
|
return "EMPTY PRUNE";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|