本文整理汇总了Java中org.sunbird.common.ElasticSearchUtil类的典型用法代码示例。如果您正苦于以下问题:Java ElasticSearchUtil类的具体用法?Java ElasticSearchUtil怎么用?Java ElasticSearchUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ElasticSearchUtil类属于org.sunbird.common包,在下文中一共展示了ElasticSearchUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertDataToElastic
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
/**
* Method to insert data to ES .
*
* @param index
* @param type
* @param identifier
* @param data
* @return
*/
private boolean insertDataToElastic(String index, String type, String identifier,
Map<String, Object> data) {
ProjectLogger
.log("making call to ES for type ,identifier ,data==" + type + " " + identifier + data);
String response = ElasticSearchUtil.createData(index, type, identifier, data);
ProjectLogger.log("Getting ES save response for type , identiofier==" + type + " " + identifier
+ " " + response);
if (!ProjectUtil.isStringNullOREmpty(response)) {
ProjectLogger.log("Data is saved successfully ES ." + type + " " + identifier);
return true;
}
ProjectLogger.log("unbale to save the data inside ES with identifier " + identifier,
LoggerEnum.INFO.name());
return false;
}
示例2: validateOrg
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
public static Map<String, Object> validateOrg(String orgId) {
try {
Map<String, Object> result =
ElasticSearchUtil.getDataByIdentifier(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.organisation.getTypeName(), orgId);
if (null == result || result.isEmpty()) {
return null;
}
ProjectLogger.log("Result:" + result.toString());
return result;
} catch (Exception e) {
ProjectLogger.log("Error occured", e);
throw new ProjectCommonException(ResponseCode.esError.getErrorCode(),
ResponseCode.esError.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode());
}
}
示例3: validateOrg
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
private Map<String, Object> validateOrg(String orgId) {
try {
Map<String, Object> result =
ElasticSearchUtil.getDataByIdentifier(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.organisation.getTypeName(), orgId);
if (null == result || result.isEmpty()) {
return null;
}
ProjectLogger.log("Result:" + result.toString());
return result;
} catch (Exception e) {
ProjectLogger.log("Error occured", e);
throw new ProjectCommonException(ResponseCode.esError.getErrorCode(),
ResponseCode.esError.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode());
}
}
示例4: getCourseBatch
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
private void getCourseBatch(Request actorMessage) {
Map<String, Object> map = (Map<String, Object>) actorMessage.getRequest().get(JsonKey.BATCH);
Map<String, Object> result =
ElasticSearchUtil.getDataByIdentifier(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.course.getTypeName(), (String) map.get(JsonKey.BATCH_ID));
Response response = new Response();
if (null != result) {
response.put(JsonKey.RESPONSE, result);
} else {
result = new HashMap<>();
response.put(JsonKey.RESPONSE, result);
}
sender().tell(response, self());
}
示例5: validateHashTagId
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
private String validateHashTagId(String hashTagId,String opType,String id) {
Map<String,Object> filters = new HashMap<>();
filters.put(JsonKey.HASHTAGID, hashTagId);
SearchDTO searchDto = new SearchDTO();
searchDto.getAdditionalProperties().put(JsonKey.FILTERS,filters);
Map<String, Object> result = ElasticSearchUtil.complexSearch(searchDto,
ProjectUtil.EsIndex.sunbird.getIndexName(), ProjectUtil.EsType.course.getTypeName());
List<Map<String, Object>> dataMapList =
(List<Map<String, Object>>) result.get(JsonKey.CONTENT);
if(opType.equalsIgnoreCase(JsonKey.CREATE)){
if(!dataMapList.isEmpty()){
throw new ProjectCommonException(ResponseCode.invalidHashTagId.getErrorCode(),
ResponseCode.invalidHashTagId.getErrorMessage(),
ResponseCode.CLIENT_ERROR.getResponseCode());
}
}else if(opType.equalsIgnoreCase(JsonKey.UPDATE) && !dataMapList.isEmpty()){
Map<String, Object> batchMap = dataMapList.get(0);
if(!(((String)batchMap.get(JsonKey.ID)).equalsIgnoreCase(id))){
throw new ProjectCommonException(ResponseCode.invalidHashTagId.getErrorCode(),
ResponseCode.invalidHashTagId.getErrorMessage(),
ResponseCode.CLIENT_ERROR.getResponseCode());
}
}
return hashTagId;
}
示例6: updateEs
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void updateEs(String userId) {
// get all records from cassandra as list and add that list to user in ElasticSearch ...
Response response = cassandraOperation.getRecordsByProperty(userSkillDbInfo.getKeySpace() , userSkillDbInfo.getTableName(), JsonKey.USER_ID , userId);
List<Map<String,Object>> responseList = (List<Map<String, Object>>) response.get(JsonKey.RESPONSE);
Map<String , Object> esMap = new HashMap<>();
esMap.put(JsonKey.SKILLS , responseList);
Map<String,Object> profile = ElasticSearchUtil.getDataByIdentifier(ProjectUtil.EsIndex.sunbird.getIndexName(), EsType.user.getTypeName(), userId);
if(null!= profile && !profile.isEmpty()){
Map<String,String> visibility = (Map<String, String>) profile.get(JsonKey.PROFILE_VISIBILITY);
if((null!=visibility && !visibility.isEmpty())&& visibility.containsKey(JsonKey.SKILLS)){
Map<String,Object> visibilityMap = ElasticSearchUtil.getDataByIdentifier(ProjectUtil.EsIndex.sunbird.getIndexName(), EsType.userprofilevisibility.getTypeName(), userId);
if (null != visibilityMap && !visibilityMap.isEmpty()) {
visibilityMap.putAll(esMap);
ElasticSearchUtil.createData(ProjectUtil.EsIndex.sunbird.getIndexName(), EsType.userprofilevisibility.getTypeName(), userId , visibilityMap);
}
}else {
ElasticSearchUtil.updateData(ProjectUtil.EsIndex.sunbird.getIndexName(), EsType.user.getTypeName(), userId , esMap);
}
}
}
示例7: esHealthCheck
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
/**
* @param actorMessage
*/
private void esHealthCheck(Request actorMessage) {
// check the elastic search
boolean isallHealthy = true;
Map<String, Object> finalResponseMap = new HashMap<>();
List<Map<String, Object>> responseList = new ArrayList<>();
responseList.add(ProjectUtil.createCheckResponse(JsonKey.ACTOR_SERVICE, false, null));
try {
boolean esResponse = ElasticSearchUtil.healthCheck();
responseList.add(ProjectUtil.createCheckResponse(JsonKey.ES_SERVICE, esResponse, null));
isallHealthy = esResponse;
} catch (Exception e) {
responseList.add(ProjectUtil.createCheckResponse(JsonKey.ES_SERVICE, true, e));
isallHealthy = false;
}
finalResponseMap.put(JsonKey.CHECKS, responseList);
finalResponseMap.put(JsonKey.NAME, "ES health check api");
if (isallHealthy) {
finalResponseMap.put(JsonKey.Healthy, true);
} else {
finalResponseMap.put(JsonKey.Healthy, false);
}
Response response = new Response();
response.getResult().put(JsonKey.RESPONSE, finalResponseMap);
sender().tell(response, self());
}
示例8: validateHashTagId
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
private String validateHashTagId(String hashTagId,String opType,String orgId) {
Map<String,Object> filters = new HashMap<>();
filters.put(JsonKey.HASHTAGID, hashTagId);
SearchDTO searchDto = new SearchDTO();
searchDto.getAdditionalProperties().put(JsonKey.FILTERS,filters);
Map<String, Object> result = ElasticSearchUtil.complexSearch(searchDto,
ProjectUtil.EsIndex.sunbird.getIndexName(), ProjectUtil.EsType.organisation.getTypeName());
List<Map<String, Object>> dataMapList =
(List<Map<String, Object>>) result.get(JsonKey.CONTENT);
if(opType.equalsIgnoreCase(JsonKey.CREATE)){
if(!dataMapList.isEmpty()){
throw new ProjectCommonException(ResponseCode.invalidHashTagId.getErrorCode(),
ResponseCode.invalidHashTagId.getErrorMessage(),
ResponseCode.CLIENT_ERROR.getResponseCode());
}
}else if(opType.equalsIgnoreCase(JsonKey.UPDATE) && !dataMapList.isEmpty()){
Map<String, Object> orgMap = dataMapList.get(0);
if(!(((String)orgMap.get(JsonKey.ID)).equalsIgnoreCase(orgId))){
throw new ProjectCommonException(ResponseCode.invalidHashTagId.getErrorCode(),
ResponseCode.invalidHashTagId.getErrorMessage(),
ResponseCode.CLIENT_ERROR.getResponseCode());
}
}
return hashTagId;
}
示例9: getOrgDetails
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
/**
* Provides the details of the organization
*/
@SuppressWarnings("unchecked")
private void getOrgDetails(Request actorMessage) {
Map<String, Object> req =
(Map<String, Object>) actorMessage.getRequest().get(JsonKey.ORGANISATION);
if (!(validateOrgRequest(req))) {
ProjectLogger.log("REQUESTED DATA IS NOT VALID");
return;
}
String orgId = (String) req.get(JsonKey.ORGANISATION_ID);
Map<String, Object> result =
ElasticSearchUtil.getDataByIdentifier(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.organisation.getTypeName(), orgId);
Response response = new Response();
if (result != null) {
response.put(JsonKey.RESPONSE, result);
} else {
result = new HashMap<>();
response.put(JsonKey.RESPONSE, result);
}
sender().tell(response, self());
}
示例10: getOrgsData
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
/**
* @param actorMessage
*/
private Map<String, Object> getOrgsData(Request actorMessage) {
Map<String, Object> requestMap = actorMessage.getRequest();
SearchDTO dto = new SearchDTO();
Map<String, Object> map = new HashMap<String, Object>();
// TODO need to check with request body what data we will get
// map.put(JsonKey.REGISTERED_ORG_ID, "some value");
// map.put(JsonKey.ROOT_ORG_ID, "");
Map<String, Object> additionalProperty = new HashMap<>();
additionalProperty.put(JsonKey.FILTERS, map);
dto.setAdditionalProperties(additionalProperty);
Map<String, Object> responseMap = ElasticSearchUtil.complexSearch(dto,
ProjectUtil.EsIndex.sunbird.getIndexName(), ProjectUtil.EsType.organisation.getTypeName());
if (requestMap != null) {
return responseMap;
}
return null;
}
示例11: getUserDetails
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
/**
* @param actorMessage
*/
private void getUserDetails(Request actorMessage) {
Map<String, Object> requestMap = actorMessage.getRequest();
SearchDTO dto = new SearchDTO();
Map<String, Object> map = new HashMap<>();
map.put(JsonKey.REGISTERED_ORG_ID, requestMap.get(JsonKey.REGISTERED_ORG_ID));
map.put(JsonKey.ROOT_ORG_ID, requestMap.get(JsonKey.ROOT_ORG_ID));
Map<String, Object> additionalProperty = new HashMap<>();
additionalProperty.put(JsonKey.FILTERS, map);
dto.setAdditionalProperties(additionalProperty);
Map<String, Object> responseMap = ElasticSearchUtil.complexSearch(dto,
ProjectUtil.EsIndex.sunbird.getIndexName(), ProjectUtil.EsType.user.getTypeName());
Response response = new Response();
response.put(JsonKey.RESPONSE, responseMap);
sender().tell(response, self());
}
示例12: updateUserLoginTime
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
/**
* This method will update user login time under cassandra and Elasticsearch.
*
* @param reqMap Map<String, Object>
* @return boolean
*/
private boolean updateUserLoginTime(Map<String, Object> reqMap) {
ProjectLogger.log("Start saving user login time==", LoggerEnum.INFO.name());
boolean response = false;
String lastLoginTime = (String) reqMap.get(JsonKey.CURRENT_LOGIN_TIME);
String userId = (String) reqMap.get(JsonKey.USER_ID);
reqMap.clear();
reqMap.put(JsonKey.LAST_LOGIN_TIME, lastLoginTime);
reqMap.put(JsonKey.CURRENT_LOGIN_TIME, Long.toString(System.currentTimeMillis()));
response = ElasticSearchUtil.updateData(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.user.getTypeName(), userId, reqMap);
Util.DbInfo usrDbInfo = Util.dbInfoMap.get(JsonKey.USER_DB);
reqMap.put(JsonKey.ID, userId);
cassandraOperation.updateRecord(usrDbInfo.getKeySpace(), usrDbInfo.getTableName(), reqMap);
ProjectLogger.log("End saving user login time== " + response, LoggerEnum.INFO.name());
return response;
}
示例13: updateUserRoleToEs
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void updateUserRoleToEs(Request actorMessage) {
List<String> roles = (List<String>) actorMessage.getRequest().get(JsonKey.ROLES);
String type = (String) actorMessage.get(JsonKey.TYPE);
String orgId = (String) actorMessage.get(JsonKey.ORGANISATION_ID);
Map<String, Object> result =
ElasticSearchUtil.getDataByIdentifier(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.user.getTypeName(), (String) actorMessage.get(JsonKey.USER_ID));
if (type.equals(JsonKey.USER)) {
result.put(JsonKey.ROLES, roles);
} else if (type.equals(JsonKey.ORGANISATION)) {
List<Map<String, Object>> roleMapList =
(List<Map<String, Object>>) result.get(JsonKey.ORGANISATIONS);
if (null != roleMapList) {
for (Map<String, Object> map : roleMapList) {
if ((orgId.equalsIgnoreCase((String) map.get(JsonKey.ORGANISATION_ID)))) {
map.put(JsonKey.ROLES, roles);
}
}
}
}
updateDataToElastic(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.user.getTypeName(), (String) result.get(JsonKey.IDENTIFIER), result);
}
示例14: removeUserOrgInfoToEs
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void removeUserOrgInfoToEs(Request actorMessage) {
Map<String, Object> orgMap = (Map<String, Object>) actorMessage.getRequest().get(JsonKey.USER);
Map<String, Object> result =
ElasticSearchUtil.getDataByIdentifier(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.user.getTypeName(), (String) orgMap.get(JsonKey.USER_ID));
if (result.containsKey(JsonKey.ORGANISATIONS) && null != result.get(JsonKey.ORGANISATIONS)) {
List<Map<String, Object>> orgMapList =
(List<Map<String, Object>>) result.get(JsonKey.ORGANISATIONS);
if (null != orgMapList) {
Iterator<Map<String, Object>> itr = orgMapList.iterator();
while (itr.hasNext()) {
Map<String, Object> map = itr.next();
if ((((String) map.get(JsonKey.USER_ID))
.equalsIgnoreCase((String) orgMap.get(JsonKey.USER_ID)))
&& (((String) map.get(JsonKey.ORGANISATION_ID))
.equalsIgnoreCase((String) orgMap.get(JsonKey.ORGANISATION_ID)))) {
itr.remove();
}
}
}
}
updateDataToElastic(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.user.getTypeName(), (String) result.get(JsonKey.IDENTIFIER), result);
}
示例15: updateUserOrgInfoToEs
import org.sunbird.common.ElasticSearchUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void updateUserOrgInfoToEs(Request actorMessage) {
Map<String, Object> orgMap = (Map<String, Object>) actorMessage.getRequest().get(JsonKey.USER);
Map<String, Object> result =
ElasticSearchUtil.getDataByIdentifier(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.user.getTypeName(), (String) orgMap.get(JsonKey.USER_ID));
if (result.containsKey(JsonKey.ORGANISATIONS) && null != result.get(JsonKey.ORGANISATIONS)) {
List<Map<String, Object>> orgMapList =
(List<Map<String, Object>>) result.get(JsonKey.ORGANISATIONS);
orgMapList.add(orgMap);
} else {
List<Map<String, Object>> mapList = new ArrayList<>();
mapList.add(orgMap);
result.put(JsonKey.ORGANISATIONS, mapList);
}
updateDataToElastic(ProjectUtil.EsIndex.sunbird.getIndexName(),
ProjectUtil.EsType.user.getTypeName(), (String) result.get(JsonKey.IDENTIFIER), result);
}