From bf0c7220bbbed99bd5bddad3a9755b1538eca032 Mon Sep 17 00:00:00 2001 From: Roman Pierson Date: Sat, 9 Dec 2023 21:44:55 +0100 Subject: [PATCH 1/4] Final release version --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 69a8f2c..6fcd9cb 100755 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ java { targetCompatibility = JavaVersion.VERSION_1_8 } -jar.archiveFileName = "vertx-elasticsearch-indexer-1.2.0.jar" +jar.archiveFileName = "vertx-elasticsearch-indexer-1.2.0-RC1.jar" java { withSourcesJar() @@ -58,7 +58,7 @@ publishing { groupId 'com.romanpierson' artifactId 'vertx-elasticsearch-indexer' - version '1.2.0' + version '1.2.0-RC1' from components.java From 70f02f0ad990b7c554ea9c3281b05d7170db97a9 Mon Sep 17 00:00:00 2001 From: Roman Pierson Date: Sat, 9 Dec 2023 21:46:19 +0100 Subject: [PATCH 2/4] Final release --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 6fcd9cb..69a8f2c 100755 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ java { targetCompatibility = JavaVersion.VERSION_1_8 } -jar.archiveFileName = "vertx-elasticsearch-indexer-1.2.0-RC1.jar" +jar.archiveFileName = "vertx-elasticsearch-indexer-1.2.0.jar" java { withSourcesJar() @@ -58,7 +58,7 @@ publishing { groupId 'com.romanpierson' artifactId 'vertx-elasticsearch-indexer' - version '1.2.0-RC1' + version '1.2.0' from components.java From ab5d085de49e075cdbf2c4ab1a27ec6046dd5da4 Mon Sep 17 00:00:00 2001 From: Roman Pierson Date: Sat, 9 Dec 2023 21:47:07 +0100 Subject: [PATCH 3/4] Typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f0ea72a..b5f8551 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ # vertx-elasticsearch-indexer A verticle that receives index data via event bus and indexes to the corresponding ElasticSearch instance(s). The whole configuration is maintained on the verticle itself. -Also Axiom.co is supoorted in latest version. +Also Axiom.co is supported in latest version. ## Technical Usage From 5c22f6dc33d9bb3ca860812b6fa2bce86ad1a4ac Mon Sep 17 00:00:00 2001 From: Roman Pierson Date: Sun, 10 Dec 2023 21:37:06 +0100 Subject: [PATCH 4/4] Fix issue with having multiple static indexes --- .../ElasticSearchIndexerVerticle.java | 65 ++++++++++--------- 1 file changed, 35 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/romanpierson/vertx/elasticsearch/indexer/verticle/ElasticSearchIndexerVerticle.java b/src/main/java/com/romanpierson/vertx/elasticsearch/indexer/verticle/ElasticSearchIndexerVerticle.java index 4bb9451..8a5d07a 100644 --- a/src/main/java/com/romanpierson/vertx/elasticsearch/indexer/verticle/ElasticSearchIndexerVerticle.java +++ b/src/main/java/com/romanpierson/vertx/elasticsearch/indexer/verticle/ElasticSearchIndexerVerticle.java @@ -84,8 +84,7 @@ public class ElasticSearchIndexerVerticle extends AbstractVerticle { private final DateFormat indexTimeStampPattern; private final String newLine = "\n"; - private String cachedStaticIndexPrefix; - private Map cachedDynamicIndexPrefix = new HashMap<>(); + private Map cachedIndexPrefix = new HashMap<>(); public enum IndexFlavour{ @@ -331,50 +330,56 @@ private HttpRequest getRequestFor(final ElasticSearchIndexerConfiguratio return request; } - private String getIndexPrefixString(final ElasticSearchIndexerConfiguration indexerConfiguration, - final long eventTimestamp) { + private String getIndexPrefixString(final ElasticSearchIndexerConfiguration indexerConfiguration, final long eventTimestamp) { + boolean isDynamicCacheIndex = false; + String cacheKey = indexerConfiguration.getIdentifier(); + if (IndexMode.DATE_PATTERN_EVENT_TIMESTAMP.equals(indexerConfiguration.getIndexMode()) || IndexMode.DATE_PATTERN_INDEX_TIMESTAMP.equals(indexerConfiguration.getIndexMode())) { - + + isDynamicCacheIndex = true; + long timestamp = IndexMode.DATE_PATTERN_EVENT_TIMESTAMP.equals(indexerConfiguration.getIndexMode()) ? eventTimestamp : System.currentTimeMillis(); - final String cacheKey = indexerConfiguration.getIdentifier() + indexDateModePattern.format(timestamp); - - if (!this.cachedDynamicIndexPrefix.containsKey(cacheKey)) { - + cacheKey = indexerConfiguration.getIdentifier() + indexDateModePattern.format(timestamp); + + } + + if (!this.cachedIndexPrefix.containsKey(cacheKey)) { + + //We still need to create that entry + // For static its straight + String formattedIndexPattern = indexerConfiguration.getIndexNameOrPattern(); + + if(isDynamicCacheIndex) { + + long timestamp = IndexMode.DATE_PATTERN_EVENT_TIMESTAMP.equals(indexerConfiguration.getIndexMode()) + ? eventTimestamp + : System.currentTimeMillis(); + ZonedDateTime tsDateTime = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timestamp), TIMEZONE_ID_UTC); // Explicitly not using a DateTimeFormatter as this would require escaping the // whole pattern - String formattedIndexPattern = indexerConfiguration.getIndexNameOrPattern() + formattedIndexPattern = indexerConfiguration.getIndexNameOrPattern() .replaceAll("yyyy", String.format("%04d", tsDateTime.getYear())) .replaceAll("MM", String.format("%02d", tsDateTime.getMonthValue())) .replaceAll("dd", String.format("%02d", tsDateTime.getDayOfMonth())); - String formattedIndexPrefix = String.format( - "{ \"index\" : { \"_index\" : \"%s\" } }%s", formattedIndexPattern, - this.newLine); - - this.cachedDynamicIndexPrefix.put(cacheKey, formattedIndexPrefix); - } - - return this.cachedDynamicIndexPrefix.get(cacheKey); - - } else { - - if (this.cachedStaticIndexPrefix == null) { - - this.cachedStaticIndexPrefix = String.format( - "{ \"index\" : { \"_index\" : \"%s\" } }%s", - indexerConfiguration.getIndexNameOrPattern(), this.newLine); - - } - - return this.cachedStaticIndexPrefix; + + // Now create the formatted index prefix fragment + String formattedIndexPrefix = String.format("{ \"index\" : { \"_index\" : \"%s\" } }%s", formattedIndexPattern, this.newLine); + + // And cache it + this.cachedIndexPrefix.put(cacheKey, formattedIndexPrefix); } + + // Now we should be able to read it from cache regardless if its static or dynamic + return this.cachedIndexPrefix.get(cacheKey); + }