add initial data
This commit is contained in:
parent
e4a3735f87
commit
4952adc28e
2 changed files with 39 additions and 0 deletions
|
@ -2,7 +2,9 @@ package org.codelibs.fess.client;
|
|||
|
||||
import static org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.newConfigs;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -17,6 +19,7 @@ import javax.annotation.PreDestroy;
|
|||
import org.apache.commons.codec.Charsets;
|
||||
import org.codelibs.core.beans.util.BeanUtil;
|
||||
import org.codelibs.core.io.FileUtil;
|
||||
import org.codelibs.core.io.ResourceUtil;
|
||||
import org.codelibs.core.lang.StringUtil;
|
||||
import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner;
|
||||
import org.codelibs.elasticsearch.runner.ElasticsearchClusterRunner.Configs;
|
||||
|
@ -339,6 +342,34 @@ public class FessEsClient implements Client {
|
|||
} else {
|
||||
logger.warn("Failed to create " + configIndex + "/" + configType + " mapping.");
|
||||
}
|
||||
|
||||
String dataPath = indexConfigPath + "/" + configIndex + "/" + configType + ".bulk";
|
||||
if (ResourceUtil.isExist(dataPath)) {
|
||||
try {
|
||||
final BulkRequestBuilder builder = client.prepareBulk();
|
||||
Arrays.stream(FileUtil.readUTF8(dataPath).split("\n")).reduce((prev, line) -> {
|
||||
if (StringUtil.isBlank(prev)) {
|
||||
if (line.startsWith("{\"index\":{")) {
|
||||
return line;
|
||||
} else if (line.startsWith("{\"update\":{")) {
|
||||
return line;
|
||||
} else if (line.startsWith("{\"delete\":{")) {
|
||||
return StringUtil.EMPTY;
|
||||
}
|
||||
} else if (prev.startsWith("{\"index\":{")) {
|
||||
IndexRequestBuilder requestBuilder = client.prepareIndex(configIndex, configType).setSource(line);
|
||||
builder.add(requestBuilder);
|
||||
}
|
||||
return StringUtil.EMPTY;
|
||||
});
|
||||
BulkResponse response = builder.execute().actionGet();
|
||||
if (response.hasFailures()) {
|
||||
logger.warn("Failed to register " + dataPath.toString() + ": " + response.buildFailureMessage());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to create " + configIndex + "/" + configType + " mapping.");
|
||||
}
|
||||
}
|
||||
} else if (logger.isDebugEnabled()) {
|
||||
logger.debug(configIndex + "/" + configType + " mapping exists.");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
{"index":{"_index":".fess_config","_type":"scheduled_job","_id":"1"}}
|
||||
{"name":"Crawler","target":"all","cronExpression":"0 0 0 * * ?","scriptType":"groovy","scriptData":"return container.getComponent(\"crawlJob\").execute(executor);","jobLogging":true,"crawler":true,"available":true,"sortOrder":0,"createdBy":"system","createdTime":0,"updatedBy":"system","updatedTime":0}
|
||||
{"index":{"_index":".fess_config","_type":"scheduled_job","_id":"2"}}
|
||||
{"name":"Minutely Tasks","target":"all","cronExpression":"0 * * * * ?","scriptType":"groovy","scriptData":"return container.getComponent(\"aggregateLogJob\").execute();","jobLogging":false,"crawler":false,"available":true,"sortOrder":0,"createdBy":"system","createdTime":0,"updatedBy":"system","updatedTime":0}
|
||||
{"index":{"_index":".fess_config","_type":"scheduled_job","_id":"3"}}
|
||||
{"name":"Hourly Tasks","target":"all","cronExpression":"0 0 * * * ?","scriptType":"groovy","scriptData":"return container.getComponent(\"updateStatsJob\").execute() + container.getComponent(\"updateHotWordJob\").execute();","jobLogging":false,"crawler":false,"available":true,"sortOrder":0,"createdBy":"system","createdTime":0,"updatedBy":"system","updatedTime":0}
|
||||
{"index":{"_index":".fess_config","_type":"scheduled_job","_id":"4"}}
|
||||
{"name":"Daily Tasks","target":"all","cronExpression":"0 0 0 * * ?","scriptType":"groovy","scriptData":"return container.getComponent(\"purgeLogJob\").execute();","jobLogging":false,"crawler":false,"available":true,"sortOrder":0,"createdBy":"system","createdTime":0,"updatedBy":"system","updatedTime":0}
|
Loading…
Add table
Reference in a new issue