fix id of document index
This commit is contained in:
parent
3d5ee5604f
commit
7e73136d27
4 changed files with 39 additions and 16 deletions
5
pom.xml
5
pom.xml
|
@ -494,6 +494,11 @@
|
|||
<artifactId>jsonic</artifactId>
|
||||
<version>1.3.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.6.3</version>
|
||||
</dependency>
|
||||
|
||||
<!-- template -->
|
||||
<dependency>
|
||||
|
|
|
@ -163,6 +163,8 @@ import org.elasticsearch.threadpool.ThreadPool;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.io.BaseEncoding;
|
||||
|
||||
public class FessEsClient implements Client {
|
||||
|
@ -396,21 +398,37 @@ public class FessEsClient implements Client {
|
|||
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\":{")) {
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Arrays.stream(FileUtil.readUTF8(dataPath).split("\n")).reduce(
|
||||
(prev, line) -> {
|
||||
try {
|
||||
if (StringUtil.isBlank(prev)) {
|
||||
Map<String, Map<String, String>> result =
|
||||
mapper.readValue(line, new TypeReference<Map<String, Map<String, String>>>() {
|
||||
});
|
||||
if (result.keySet().contains("index")) {
|
||||
return line;
|
||||
} else if (result.keySet().contains("update")) {
|
||||
return line;
|
||||
} else if (result.keySet().contains("delete")) {
|
||||
return StringUtil.EMPTY;
|
||||
}
|
||||
} else {
|
||||
Map<String, Map<String, String>> result =
|
||||
mapper.readValue(prev, new TypeReference<Map<String, Map<String, String>>>() {
|
||||
});
|
||||
if (result.keySet().contains("index")) {
|
||||
final IndexRequestBuilder requestBuilder =
|
||||
client.prepareIndex(configIndex, configType, result.get("index").get("_id"))
|
||||
.setSource(line);
|
||||
builder.add(requestBuilder);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.warn("Failed to parse " + configIndex + "/" + configType + " mapping.");
|
||||
}
|
||||
return StringUtil.EMPTY;
|
||||
}
|
||||
} else if (prev.startsWith("{\"index\":{")) {
|
||||
final IndexRequestBuilder requestBuilder = client.prepareIndex(configIndex, configType).setSource(line);
|
||||
builder.add(requestBuilder);
|
||||
}
|
||||
return StringUtil.EMPTY;
|
||||
});
|
||||
});
|
||||
final BulkResponse response = builder.execute().actionGet();
|
||||
if (response.hasFailures()) {
|
||||
logger.warn("Failed to register " + dataPath.toString() + ": " + response.buildFailureMessage());
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
{"index":{"_index":".fess_user","_type":"role","_id":"YWRtaW4="}}
|
||||
{"name":"admin","id":"YWRtaW4="}
|
||||
{"name":"admin"}
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
{"index":{"_index":".fess_user","_type":"user","_id":"YWRtaW4="}}
|
||||
{"password":"8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918","roles":["YWRtaW4="],"name":"admin","id":"YWRtaW4="}
|
||||
{"password":"8c6976e5b5410415bde908bd4dee15dfb167a9c873fc4bb8a81f6f2ab448a918","roles":["YWRtaW4="],"name":"admin"}
|
||||
|
|
Loading…
Add table
Reference in a new issue