use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.
the class AdminUpgradeAction method upgradeFrom13_16.
private void upgradeFrom13_16() {
final String[] configIndices = { //
"fess_config.access_token", //
"fess_config.bad_word", //
"fess_config.boost_document_rule", //
"fess_config.crawling_info", //
"fess_config.crawling_info_param", //
"fess_config.data_config", //
"fess_config.duplicate_host", //
"fess_config.elevate_word", //
"fess_config.elevate_word_to_label", //
"fess_config.failure_url", //
"fess_config.file_authentication", //
"fess_config.file_config", //
"fess_config.job_log", //
"fess_config.key_match", //
"fess_config.label_type", //
"fess_config.path_mapping", //
"fess_config.related_content", //
"fess_config.related_query", //
"fess_config.request_header", //
"fess_config.role_type", //
"fess_config.scheduled_job", //
"fess_config.thumbnail_queue", //
"fess_config.web_authentication", //
"fess_config.web_config", //
"fess_user.group", //
"fess_user.role", //
"fess_user.user", //
"configsync" };
final String[] crawlerIndices = { //
".crawler.data", //
".crawler.filter", //
".crawler.queue" };
final SearchEngineClient client = ComponentUtil.getSearchEngineClient();
for (final String index : configIndices) {
final String oldIndex = "." + index;
if (client.existsIndex(oldIndex) && client.existsIndex(index)) {
logger.info("Copying from {} to {}", oldIndex, index);
if (!client.reindex(oldIndex, index, false)) {
logger.warn("Failed to copy from {} to {}", oldIndex, index);
}
} else if (logger.isDebugEnabled()) {
if (!client.existsIndex(oldIndex)) {
logger.debug("{} does not exist.", oldIndex);
}
if (!client.existsIndex(index)) {
logger.debug("{} does not exist.", index);
}
}
}
for (final String index : crawlerIndices) {
if (client.existsIndex(index)) {
if (client.deleteIndex(index)) {
logger.warn("Deleted {}.", index);
} else {
logger.warn("Failed to delete {}.", index);
}
} else if (logger.isDebugEnabled()) {
logger.debug("{} does not exist.", index);
}
}
}
use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.
the class JsonApiManager method processPingRequest.
protected void processPingRequest(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) {
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
int status;
Exception err = null;
try {
final PingResponse pingResponse = searchEngineClient.ping();
status = pingResponse.getStatus();
writeJsonResponse(status, "\"message\":" + pingResponse.getMessage());
} catch (final Exception e) {
status = 9;
err = e;
if (logger.isDebugEnabled()) {
logger.debug("Failed to process a ping request.", e);
}
writeJsonResponse(status, null, err);
}
}
use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.
the class FileListIndexUpdateCallbackImpl method deleteDocument.
protected boolean deleteDocument(final Map<String, String> paramMap, final Map<String, Object> dataMap) {
if (logger.isDebugEnabled()) {
logger.debug("Deleting {}", dataMap);
}
final FessConfig fessConfig = ComponentUtil.getFessConfig();
// required check
if (!dataMap.containsKey(fessConfig.getIndexFieldUrl()) || dataMap.get(fessConfig.getIndexFieldUrl()) == null) {
logger.warn("Could not delete a doc. Invalid data: {}", dataMap);
return false;
}
synchronized (indexUpdateCallback) {
final long maxAccessCount = getMaxAccessCount(paramMap, dataMap);
final String url = dataMap.get(fessConfig.getIndexFieldUrl()).toString();
if (maxAccessCount != 1L) {
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
final long count = indexingHelper.deleteDocumentByQuery(searchEngineClient, QueryBuilders.prefixQuery(fessConfig.getIndexFieldUrl(), url));
if (logger.isDebugEnabled()) {
logger.debug("Deleted {} docs for {}*", count, url);
}
} else {
deleteUrlList.add(url);
if (deleteUrlList.size() >= maxDeleteDocumentCacheSize) {
deleteDocuments();
}
}
}
return true;
}
use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.
the class IndexUpdateCallbackImpl method commit.
@Override
public void commit() {
synchronized (docList) {
if (!docList.isEmpty()) {
final IndexingHelper indexingHelper = ComponentUtil.getIndexingHelper();
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
indexingHelper.sendDocuments(searchEngineClient, docList);
}
}
}
use of org.codelibs.fess.es.client.SearchEngineClient in project fess by codelibs.
the class SuggestHelper method init.
@PostConstruct
public void init() {
if (logger.isDebugEnabled()) {
logger.debug("Initialize {}", this.getClass().getSimpleName());
}
fessConfig = ComponentUtil.getFessConfig();
split(fessConfig.getSuggestFieldContents(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(contentFieldNameSet::add));
split(fessConfig.getSuggestFieldTags(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(tagFieldNameSet::add));
split(fessConfig.getSuggestFieldRoles(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(roleFieldNameSet::add));
contentFieldList = Arrays.asList(stream(fessConfig.getSuggestFieldContents()).get(stream -> stream.toArray(n -> new String[n])));
final SearchEngineClient searchEngineClient = ComponentUtil.getSearchEngineClient();
searchEngineClient.admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(fessConfig.getIndexHealthTimeout());
final SuggestSettingsBuilder settingsBuilder = SuggestSettings.builder();
settingsBuilder.addInitialSettings("elasticsearch.type", fessConfig.getFesenType());
settingsBuilder.bulkTimeout(fessConfig.getIndexBulkTimeout());
settingsBuilder.clusterTimeout(fessConfig.getIndexHealthTimeout());
settingsBuilder.indexTimeout(fessConfig.getIndexIndexTimeout());
settingsBuilder.indicesTimeout(fessConfig.getIndexIndicesTimeout());
settingsBuilder.searchTimeout(fessConfig.getIndexSearchTimeout());
suggester = Suggester.builder().settings(settingsBuilder).build(searchEngineClient, fessConfig.getIndexDocumentSuggestIndex());
suggester.settings().array().delete(SuggestSettings.DefaultKeys.SUPPORTED_FIELDS);
split(fessConfig.getSuggestFieldIndexContents(), ",").of(stream -> stream.filter(StringUtil::isNotBlank).forEach(field -> {
try {
suggester.settings().array().add(SuggestSettings.DefaultKeys.SUPPORTED_FIELDS, field);
} catch (final SuggestSettingsException e) {
logger.warn("Failed to add {}", field, e);
}
}));
suggester.createIndexIfNothing();
if (ComponentUtil.hasPopularWordHelper()) {
popularWordHelper = ComponentUtil.getPopularWordHelper();
}
}
Aggregations