diff --git a/.circleci/config.yml b/.circleci/config.yml
index 62ff1e9373..e8e8f8c236 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -2,7 +2,11 @@ version: 2.1
jobs:
build:
machine:
- image: ubuntu-2004:202008-01
+ image: ubuntu-2004:202201-02
+ # https://circleci.com/docs/parallelism-faster-jobs/
+ # parallelism: 4
+ # The resource_class feature allows configuring CPU and RAM resources for each job. Different resource classes are available for different executors. https://circleci.com/docs/2.0/configuration-reference/#resourceclass
+ resource_class: large
steps:
- checkout
- restore_cache:
diff --git a/core/es-utils/pom.xml b/core/es-utils/pom.xml
index d501570052..dd0ad4a2ed 100644
--- a/core/es-utils/pom.xml
+++ b/core/es-utils/pom.xml
@@ -29,7 +29,7 @@
org.elasticsearch.client
elasticsearch-rest-high-level-client
- 6.8.22
+ 7.17.13
junit
diff --git a/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java b/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java
index 312db6be6f..e548cb654e 100644
--- a/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java
+++ b/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchHelper.java
@@ -717,7 +717,7 @@ public static Map getSearchResponseMap(
long count = 0;
if (response != null) {
SearchHits hits = response.getHits();
- count = hits.getTotalHits();
+ count = hits.getTotalHits().value;
for (SearchHit hit : hits) {
esSource.add(hit.getSourceAsMap());
diff --git a/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java b/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java
index 751f134c29..c462ac430a 100644
--- a/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java
+++ b/core/es-utils/src/main/java/org/sunbird/common/ElasticSearchRestHighImpl.java
@@ -1,12 +1,6 @@
package org.sunbird.common;
import akka.dispatch.Futures;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
@@ -26,7 +20,11 @@
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.update.UpdateRequest;
import org.elasticsearch.action.update.UpdateResponse;
-import org.elasticsearch.index.query.*;
+import org.elasticsearch.client.RequestOptions;
+import org.elasticsearch.index.query.BoolQueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
+import org.elasticsearch.index.query.SimpleQueryStringBuilder;
+import org.elasticsearch.index.query.TermQueryBuilder;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
import org.elasticsearch.search.builder.SearchSourceBuilder;
@@ -44,6 +42,9 @@
import scala.concurrent.Future;
import scala.concurrent.Promise;
+import java.util.*;
+import java.util.stream.Collectors;
+
/**
* This class will provide all required operation for elastic search.
*
@@ -53,6 +54,8 @@ public class ElasticSearchRestHighImpl implements ElasticSearchService {
private static final String ERROR = "ERROR";
private static final LoggerUtil logger = new LoggerUtil(ElasticSearchRestHighImpl.class);
+// private static ObjectMapper mapper = new ObjectMapper();
+
/**
* This method will put a new data entry inside Elastic search. identifier value becomes _id
* inside ES, so every time provide a unique value while saving it.
@@ -64,23 +67,16 @@ public class ElasticSearchRestHighImpl implements ElasticSearchService {
* @return Future which contains identifier for created data
*/
@Override
- public Future save(
- String index, String identifier, Map data, RequestContext context) {
+ public Future save(String index, String identifier, Map data, RequestContext context) {
long startTime = System.currentTimeMillis();
Promise promise = Futures.promise();
- logger.debug(
- context,
+ logger.debug(context,
"ElasticSearchUtilRest:save: method started at ==" + startTime + " for Index " + index);
if (StringUtils.isBlank(identifier) || StringUtils.isBlank(index)) {
- logger.info(
- context,
+ logger.info(context,
"ElasticSearchRestHighImpl:save: "
- + "Identifier or Index value is null or empty, identifier : "
- + ""
- + identifier
- + ",index: "
- + index
- + ",not able to save data.");
+ + "Identifier or Index value is null or empty, identifier : " + identifier
+ + ",index: " + index + ",not able to save data.");
promise.success(ERROR);
return promise.future();
}
@@ -92,47 +88,32 @@ public Future save(
new ActionListener() {
@Override
public void onResponse(IndexResponse indexResponse) {
- logger.info(
- context,
- "ElasticSearchRestHighImpl:save: Success for index : "
- + index
- + ", identifier :"
- + identifier);
+ logger.info(context,
+ "ElasticSearchRestHighImpl:save: Success for index : " + index
+ + ", identifier :" + identifier);
promise.success(indexResponse.getId());
- logger.debug(
- context,
- "ElasticSearchRestHighImpl:save: method end at =="
- + System.currentTimeMillis()
- + " for Index "
- + index
- + " ,Total time elapsed = "
- + calculateEndTime(startTime));
+ logger.debug(context,
+ "ElasticSearchRestHighImpl:save: method end at ==" + System.currentTimeMillis()
+ + " for Index " + index
+ + " ,Total time elapsed = " + calculateEndTime(startTime));
}
@Override
public void onFailure(Exception e) {
promise.failure(e);
- logger.error(
- context,
+ logger.error(context,
"ElasticSearchRestHighImpl:save: "
- + "Error while saving "
- + index
- + " id : "
- + identifier,
- e);
- logger.debug(
- context,
- "ElasticSearchRestHighImpl:save: method end at =="
- + System.currentTimeMillis()
- + " for INdex "
- + index
- + " ,Total time elapsed = "
- + calculateEndTime(startTime));
+ + "Error while saving " + index
+ + " id : " + identifier, e);
+ logger.debug(context,
+ "ElasticSearchRestHighImpl:save: method end at ==" + System.currentTimeMillis()
+ + " for INdex " + index
+ + " ,Total time elapsed = " + calculateEndTime(startTime));
}
};
- ConnectionManager.getRestClient().indexAsync(indexRequest, listener);
+ ConnectionManager.getRestClient().indexAsync(indexRequest, RequestOptions.DEFAULT, listener);
return promise.future();
}
@@ -141,59 +122,47 @@ public void onFailure(Exception e) {
* This method will update data entry inside Elastic search, using identifier and provided data .
*
* @param index String ES index name
- * @param identifier ES column identifier as an String
- * @param data Map
+ * @param documentId ES column identifier as an String
+ * @param document Map
* @param context
* @return true or false
*/
@Override
- public Future update(
- String index, String identifier, Map data, RequestContext context) {
+ public Future update(String index, String documentId, Map document, RequestContext context) {
long startTime = System.currentTimeMillis();
- logger.debug(
- context,
- "ElasticSearchRestHighImpl:update: method started at =="
- + startTime
- + " for Index "
- + index);
+ logger.debug(context,
+ "ElasticSearchRestHighImpl:update: method started at ==" + startTime
+ + " for Index " + index);
Promise promise = Futures.promise();
- data.put("identifier", identifier);
+ document.put("identifier", documentId);
- if (!StringUtils.isBlank(index) && !StringUtils.isBlank(identifier) && data != null) {
- UpdateRequest updateRequest = new UpdateRequest(index, _DOC, identifier).doc(data);
+ if (!StringUtils.isBlank(index) && !StringUtils.isBlank(documentId)) {
+// Map updatedDoc = checkDocStringLength(document);
+ IndexRequest indexRequest = new IndexRequest(index).id(documentId).source(document);
+ UpdateRequest updateRequest = new UpdateRequest().index(index).id(documentId).doc(document).upsert(indexRequest);
ActionListener listener =
new ActionListener() {
@Override
public void onResponse(UpdateResponse updateResponse) {
promise.success(true);
- logger.info(
- context,
- "ElasticSearchRestHighImpl:update: Success with "
- + updateResponse.getResult()
- + " response from elastic search for index"
- + index
- + ",identifier : "
- + identifier);
- logger.debug(
- context,
+ logger.info(context,
+ "ElasticSearchRestHighImpl:update: Success with " + updateResponse.getResult()
+ + " response from elastic search for index" + index
+ + ",documentId : " + documentId);
+ logger.debug(context,
"ElasticSearchRestHighImpl:update: method end =="
- + " for INdex "
- + index
- + " ,Total time elapsed = "
- + calculateEndTime(startTime));
+ + " for INdex " + index
+ + " ,Total time elapsed = " + calculateEndTime(startTime));
}
@Override
public void onFailure(Exception e) {
- logger.error(
- context,
- "ElasticSearchRestHighImpl:update: exception occured:" + e.getMessage(),
- e);
+ logger.error(context, "ElasticSearchRestHighImpl:update: exception occured:" + e.getMessage(), e);
promise.failure(e);
}
};
- ConnectionManager.getRestClient().updateAsync(updateRequest, listener);
+ ConnectionManager.getRestClient().updateAsync(updateRequest, RequestOptions.DEFAULT, listener);
} else {
logger.info(context, "ElasticSearchRestHighImpl:update: Requested data is invalid.");
@@ -216,13 +185,9 @@ public Future