mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
es 批量提交修改
This commit is contained in:
@@ -72,6 +72,7 @@ public class ESTemplate {
|
|||||||
getBulk().add(transportClient.prepareIndex(mapping.get_index(), mapping.get_type(), pkVal.toString())
|
getBulk().add(transportClient.prepareIndex(mapping.get_index(), mapping.get_type(), pkVal.toString())
|
||||||
.setSource(esFieldData));
|
.setSource(esFieldData));
|
||||||
}
|
}
|
||||||
|
commitBulk();
|
||||||
} else {
|
} else {
|
||||||
SearchResponse response = transportClient.prepareSearch(mapping.get_index())
|
SearchResponse response = transportClient.prepareSearch(mapping.get_index())
|
||||||
.setTypes(mapping.get_type())
|
.setTypes(mapping.get_type())
|
||||||
@@ -81,9 +82,10 @@ public class ESTemplate {
|
|||||||
for (SearchHit hit : response.getHits()) {
|
for (SearchHit hit : response.getHits()) {
|
||||||
getBulk().add(transportClient.prepareUpdate(mapping.get_index(), mapping.get_type(), hit.getId())
|
getBulk().add(transportClient.prepareUpdate(mapping.get_index(), mapping.get_type(), hit.getId())
|
||||||
.setDoc(esFieldData));
|
.setDoc(esFieldData));
|
||||||
|
commitBulk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commitBulk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,6 +151,7 @@ public class ESTemplate {
|
|||||||
public void delete(ESMapping mapping, Object pkVal, Map<String, Object> esFieldData) {
|
public void delete(ESMapping mapping, Object pkVal, Map<String, Object> esFieldData) {
|
||||||
if (mapping.get_id() != null) {
|
if (mapping.get_id() != null) {
|
||||||
getBulk().add(transportClient.prepareDelete(mapping.get_index(), mapping.get_type(), pkVal.toString()));
|
getBulk().add(transportClient.prepareDelete(mapping.get_index(), mapping.get_type(), pkVal.toString()));
|
||||||
|
commitBulk();
|
||||||
} else {
|
} else {
|
||||||
SearchResponse response = transportClient.prepareSearch(mapping.get_index())
|
SearchResponse response = transportClient.prepareSearch(mapping.get_index())
|
||||||
.setTypes(mapping.get_type())
|
.setTypes(mapping.get_type())
|
||||||
@@ -158,9 +161,10 @@ public class ESTemplate {
|
|||||||
for (SearchHit hit : response.getHits()) {
|
for (SearchHit hit : response.getHits()) {
|
||||||
getBulk().add(transportClient.prepareUpdate(mapping.get_index(), mapping.get_type(), hit.getId())
|
getBulk().add(transportClient.prepareUpdate(mapping.get_index(), mapping.get_type(), hit.getId())
|
||||||
.setDoc(esFieldData));
|
.setDoc(esFieldData));
|
||||||
|
commitBulk();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
commitBulk();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,7 +190,7 @@ public class ESTemplate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 如果大于批量则提交批次
|
* 如果大于批量数则提交批次
|
||||||
*/
|
*/
|
||||||
private void commitBulk() {
|
private void commitBulk() {
|
||||||
if (getBulk().numberOfActions() >= MAX_BATCH_SIZE) {
|
if (getBulk().numberOfActions() >= MAX_BATCH_SIZE) {
|
||||||
|
|||||||
Reference in New Issue
Block a user