Commit 25c5f0d6 by xmh

添加刷新机制

1 parent b641d4d3
...@@ -175,7 +175,9 @@ public class PersonService { ...@@ -175,7 +175,9 @@ public class PersonService {
if (bulkRequest.requests().size() == 0) { if (bulkRequest.requests().size() == 0) {
return null; return null;
} }
return client.bulk(bulkRequest, RequestOptions.DEFAULT); BulkResponse bulk = client.bulk(bulkRequest, RequestOptions.DEFAULT);
poolService.refreshPool(poolId);
return bulk;
} }
/** /**
......
...@@ -10,6 +10,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -10,6 +10,8 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.ElasticsearchStatusException;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.*; import org.elasticsearch.client.*;
...@@ -170,6 +172,12 @@ public class PoolService { ...@@ -170,6 +172,12 @@ public class PoolService {
} }
} }
public void refreshPool(String... poolIds) throws IOException {
RefreshRequest refreshRequest = new RefreshRequest(poolIds);
RefreshResponse refresh = client.indices().refresh(refreshRequest, RequestOptions.DEFAULT);
log.info("刷新索引:{},成功:{},失败:{}", poolIds, refresh.getSuccessfulShards(), refresh.getFailedShards());
}
public XContentBuilder getCreateIndexContentBuilder() throws IOException { public XContentBuilder getCreateIndexContentBuilder() throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder(); XContentBuilder builder = XContentFactory.jsonBuilder();
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!