diff --git a/core/pom.xml b/core/pom.xml
index 17618324f..cc584d87e 100644
--- a/core/pom.xml
+++ b/core/pom.xml
@@ -14,8 +14,106 @@
pom
core
+
+
+ 11
+ 11
+ 11
+
+
+ UTF-8
+ UTF-8
+
+
+ 3.7.0
+
+
+ 7.10.2
+
+
+ 4.5.14
+ 4.4.16
+ 4.1.5
+
+
+ 2.13.5
+
+
+ 1.2.3
+ 6.6
+
+
+ 3.2.2
+ 3.12.0
+
+
+ 4.13.1
+ 2.0.9
+
+
+ 3.8.1
+ 3.0.0
+ 0.8.7
+ 1.1.1
+
+
sunbird-cassandra-utils
+ sunbird-es-utils
+
+ ${basedir}/src/main/java
+ ${basedir}/src/test/java
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ 11
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+ --illegal-access=warn
+
+
+
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ ${jacoco-maven-plugin.version}
+
+ ${basedir}/target/coverage-reports/jacoco-unit.exec
+ ${basedir}/target/coverage-reports/jacoco-unit.exec
+
+
+
+ jacoco-initialize
+
+ prepare-agent
+
+
+
+ jacoco-site
+ package
+
+ report
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/core/sunbird-cassandra-utils/pom.xml b/core/sunbird-cassandra-utils/pom.xml
index 1e8d1febb..60a29d73c 100644
--- a/core/sunbird-cassandra-utils/pom.xml
+++ b/core/sunbird-cassandra-utils/pom.xml
@@ -10,25 +10,14 @@
org.sunbird
sunbird-cassandra-utils
1.0-SNAPSHOT
- sunbird-cassandra-utils
-
-
- 11
- 11
- 11
- UTF-8
- UTF-8
- 1.1.1
- 3.7.0
- 2.13.5
-
+ Sunbird Cassandra Utils
com.datastax.cassandra
cassandra-driver-core
- 3.7.0
+ ${cassandra.driver.version}
shaded
@@ -66,12 +55,12 @@
commons-collections
commons-collections
- 3.2.2
+ ${commons-collections.version}
org.apache.commons
commons-lang3
- 3.12.0
+ ${commons-lang3.version}
diff --git a/core/sunbird-es-utils/pom.xml b/core/sunbird-es-utils/pom.xml
new file mode 100644
index 000000000..0758f34df
--- /dev/null
+++ b/core/sunbird-es-utils/pom.xml
@@ -0,0 +1,161 @@
+
+
+
+
+ org.sunbird
+ core
+ 1.0-SNAPSHOT
+
+
+ 4.0.0
+ sunbird-es-utils
+ 1.0-SNAPSHOT
+ Sunbird ElasticSearch Utils
+
+
+
+
+ org.elasticsearch.client
+ elasticsearch-rest-high-level-client
+ ${elasticsearch.version}
+
+
+ org.apache.httpcomponents
+ httpasyncclient
+
+
+ org.apache.httpcomponents
+ httpcore-nio
+
+
+ org.apache.httpcomponents
+ httpclient
+
+
+ org.apache.httpcomponents
+ httpcore
+
+
+
+
+
+ org.elasticsearch.client
+ transport
+ ${elasticsearch.version}
+
+
+ io.netty
+ *
+
+
+
+
+
+
+ org.apache.httpcomponents
+ httpasyncclient
+ ${httpcomponents.httpasyncclient.version}
+
+
+
+ org.apache.httpcomponents
+ httpcore-nio
+ ${httpcomponents.httpcore.version}
+
+
+
+ org.apache.httpcomponents
+ httpclient
+ ${httpcomponents.httpclient.version}
+
+
+
+ org.apache.httpcomponents
+ httpcore
+ ${httpcomponents.httpcore.version}
+
+
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback.version}
+
+
+
+ ch.qos.logback
+ logback-core
+ ${logback.version}
+
+
+
+ net.logstash.logback
+ logstash-logback-encoder
+ ${logstash-logback-encoder.version}
+
+
+ com.fasterxml.jackson.core
+ jackson-core
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+
+
+ com.fasterxml.jackson.core
+ jackson-annotations
+
+
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
+
+
+
+ org.sunbird
+ common-util
+ 0.0.1-SNAPSHOT
+
+
+ io.netty
+ *
+
+
+
+
+
+
+ junit
+ junit
+ ${junit.version}
+ test
+
+
+
+ org.powermock
+ powermock-module-junit4
+ ${powermock.version}
+ test
+
+
+ junit
+ junit
+
+
+
+
+
+ org.powermock
+ powermock-api-mockito2
+ ${powermock.version}
+ test
+
+
+
diff --git a/course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java b/core/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java
similarity index 51%
rename from course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java
rename to core/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java
index 826439475..51c372d88 100644
--- a/course-mw/sunbird-util/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java
+++ b/core/sunbird-es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java
@@ -1,15 +1,35 @@
package org.sunbird.common;
-import org.apache.pekko.util.Timeout;
-import com.typesafe.config.Config;
+import static org.sunbird.common.models.util.ProjectUtil.isNotNull;
+
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.lucene.search.join.ScoreMode;
+import org.apache.pekko.util.Timeout;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
-import org.elasticsearch.index.query.*;
+import org.elasticsearch.index.query.BoolQueryBuilder;
+import org.elasticsearch.index.query.ExistsQueryBuilder;
+import org.elasticsearch.index.query.MatchQueryBuilder;
+import org.elasticsearch.index.query.QueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.index.query.RangeQueryBuilder;
+import org.elasticsearch.index.query.TermQueryBuilder;
+import org.elasticsearch.index.query.TermsQueryBuilder;
+import org.elasticsearch.common.unit.Fuzziness;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.aggregations.AggregationBuilders;
@@ -20,132 +40,142 @@
import org.elasticsearch.search.sort.SortOrder;
import org.sunbird.common.models.util.JsonKey;
import org.sunbird.common.models.util.LoggerUtil;
-import org.sunbird.common.util.ConfigUtil;
import org.sunbird.dto.SearchDTO;
import scala.concurrent.Await;
import scala.concurrent.Future;
-import java.math.BigInteger;
-import java.util.*;
-import java.util.Map.Entry;
-import java.util.concurrent.TimeUnit;
-import java.util.stream.Collectors;
-
-import static org.sunbird.common.models.util.ProjectUtil.isNotNull;
-
/**
- * This class will provide all required operation for elastic search.
- *
- * @author arvind
- * @author Manzarul
- * @author mayank:github.com/iostream04
+ * Helper class for Elasticsearch operations.
+ * Provides utility methods for query construction, response parsing, and aggregation handling.
*/
public class ElasticSearchHelper {
+ /** Less than or equal to operator constant. */
public static final String LTE = "<=";
+
+ /** Less than operator constant. */
public static final String LT = "<";
+
+ /** Greater than or equal to operator constant. */
public static final String GTE = ">=";
+
+ /** Greater than operator constant. */
public static final String GT = ">";
+
+ /** Ascending sort order constant. */
public static final String ASC_ORDER = "ASC";
+
+ /** Starts with string operation constant. */
public static final String STARTS_WITH = "startsWith";
+
+ /** Ends with string operation constant. */
public static final String ENDS_WITH = "endsWith";
+
+ /** Soft mode constant for constraints. */
public static final String SOFT_MODE = "soft";
+
+ /** Suffix for raw field access in Elasticsearch. */
public static final String RAW_APPEND = ".raw";
+
+ /** Cache for verifying index existence. */
protected static Map indexMap = new HashMap<>();
+
+ /** Cache for verifying type existence. */
protected static Map typeMap = new HashMap<>();
- protected static final String ES_CONFIG_FILE = "elasticsearch.conf";
- private static Config config = ConfigUtil.getConfig(ES_CONFIG_FILE);
+
+ /** Default wait time in seconds for async operations. */
public static final int WAIT_TIME = 5;
+
+ /** Timeout configuration for async operations. */
public static Timeout timeout = new Timeout(WAIT_TIME, TimeUnit.SECONDS);
+
+ /** Valid results for upsert operations. */
public static final List upsertResults =
new ArrayList<>(Arrays.asList("CREATED", "UPDATED", "NOOP"));
+
+ /** Default document type for Elasticsearch 6.x/7.x compatibility. */
private static final String _DOC = "_doc";
- private static LoggerUtil logger = new LoggerUtil(ElasticSearchHelper.class);
+
+ private static final LoggerUtil logger = new LoggerUtil(ElasticSearchHelper.class);
+ /** Private constructor to prevent instantiation of utility class. */
private ElasticSearchHelper() {}
/**
- * This method will return the object after getting complete future.
+ * Waits for and returns the result from a Scala Future.
*
- * @param future
- * @return Object which future inherits
+ * @param future The Scala Future to wait for
+ * @return The result object from the future, or null if an error occurs
*/
@SuppressWarnings("unchecked")
public static Object getResponseFromFuture(Future future) {
try {
- Object result = Await.result(future, timeout.duration());
- return result;
+ if (future != null) {
+ return Await.result(future, timeout.duration());
+ }
} catch (Exception e) {
- logger.error( null,
- "ElasticSearchHelper:getResponseFromFuture: error occured " , e);
+ logger.error(null, "ElasticSearchHelper:getResponseFromFuture: Error occurred while waiting for future result", e);
}
return null;
}
/**
- * This method adds aggregations to the incoming SearchRequestBuilder object
+ * Adds aggregations to the SearchRequestBuilder based on the provided facets.
*
- * @param searchRequestBuilder which will be updated with facets if any present
- * @param facets Facets provide aggregated data based on a search query
- * @return SearchRequestBuilder
+ * @param searchRequestBuilder The builder to add aggregations to
+ * @param facets List of facets configuration
+ * @return The updated SearchRequestBuilder
*/
public static SearchRequestBuilder addAggregations(
SearchRequestBuilder searchRequestBuilder, List