This is an automated email from the ASF dual-hosted git repository.
kezhenxu94 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new 9c46d6f Fix es normal index couldn't apply mapping and update (#8661)
9c46d6f is described below
commit 9c46d6f8d4d9ef8f5becaa05930fd0a7ac3ad346
Author: Kai <[email protected]>
AuthorDate: Fri Mar 11 10:24:17 2022 +0800
Fix es normal index couldn't apply mapping and update (#8661)
---
CHANGES.md | 1 +
.../elasticsearch/base/StorageEsInstaller.java | 31 +++++++++++++++++++---
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/CHANGES.md b/CHANGES.md
index 0b728dd..24ebb43 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -93,6 +93,7 @@ Release Notes.
* [Breaking Change] Deprecate `All` from OAL source.
* [Breaking Change] Remove `SRC_ALL: 'All'` from OAL grammar tree.
* Remove `all_heatmap` and `all_percentile` metrics.
+* Fix es normal index couldn't apply mapping and update.
#### UI
diff --git
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
index a6a87e9..417d3cc 100644
---
a/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
+++
b/oap-server/server-storage-plugin/storage-elasticsearch-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/elasticsearch/base/StorageEsInstaller.java
@@ -68,7 +68,15 @@ public class StorageEsInstaller extends ModelInstaller {
String tableName = IndexController.INSTANCE.getTableName(model);
IndexController.LogicIndicesRegister.registerRelation(model.getName(),
tableName);
if (!model.isTimeSeries()) {
- return esClient.isExistsIndex(tableName);
+ boolean exist = esClient.isExistsIndex(tableName);
+ if (exist) {
+ Mappings historyMapping = esClient.getIndex(tableName)
+ .map(Index::getMappings)
+ .orElseGet(Mappings::new);
+ structures.putStructure(tableName, historyMapping);
+ exist = structures.containsStructure(tableName,
createMapping(model));
+ }
+ return exist;
}
boolean templateExists = esClient.isExistsTemplate(tableName);
final Optional<IndexTemplate> template =
esClient.getTemplate(tableName);
@@ -102,11 +110,28 @@ public class StorageEsInstaller extends ModelInstaller {
private void createNormalTable(Model model) throws StorageException {
ElasticSearchClient esClient = (ElasticSearchClient) client;
String tableName = IndexController.INSTANCE.getTableName(model);
+ Mappings mapping = createMapping(model);
if (!esClient.isExistsIndex(tableName)) {
- boolean isAcknowledged = esClient.createIndex(tableName);
+ Map<String, Object> settings = createSetting(model);
+ boolean isAcknowledged = esClient.createIndex(tableName, mapping,
settings);
log.info("create {} index finished, isAcknowledged: {}",
tableName, isAcknowledged);
if (!isAcknowledged) {
- throw new StorageException("create " + tableName + " time
series index failure, ");
+ throw new StorageException("create " + tableName + " index
failure, ");
+ }
+ } else {
+ Mappings historyMapping = esClient.getIndex(tableName)
+ .map(Index::getMappings)
+ .orElseGet(Mappings::new);
+ structures.putStructure(tableName, mapping);
+ Mappings appendMapping = structures.diffStructure(tableName,
historyMapping);
+ if (appendMapping.getProperties() != null &&
!appendMapping.getProperties().isEmpty()) {
+ boolean isAcknowledged =
esClient.updateIndexMapping(tableName, appendMapping);
+ log.info("update {} index finished, isAcknowledged: {}, append
mappings: {}", tableName,
+ isAcknowledged, appendMapping
+ );
+ if (!isAcknowledged) {
+ throw new StorageException("update " + tableName + " index
failure");
+ }
}
}
}