@@ -25,7 +25,10 @@ public void create(PhotonDoc doc, int objectId) {
25
25
.index (PhotonIndex .NAME )
26
26
.id (doc .getUid (objectId ))
27
27
.document (doc )));
28
- ++todoDocuments ;
28
+
29
+ if (++todoDocuments > 10000 ) {
30
+ updateDocuments ();
31
+ }
29
32
}
30
33
31
34
@ Override
@@ -34,7 +37,10 @@ public void delete(long docId, int objectId) {
34
37
.delete (d -> d
35
38
.index (PhotonIndex .NAME )
36
39
.id (PhotonDoc .makeUid (docId , objectId ))));
37
- ++todoDocuments ;
40
+
41
+ if (++todoDocuments > 10000 ) {
42
+ updateDocuments ();
43
+ }
38
44
}
39
45
40
46
@ Override
@@ -58,21 +64,19 @@ public void finish() {
58
64
}
59
65
60
66
private void updateDocuments () {
61
- if (todoDocuments == 0 ) {
62
- return ;
63
- }
67
+ if (todoDocuments > 0 ) {
68
+ try {
69
+ var response = client . bulk ( bulkRequest . build ());
64
70
65
- try {
66
- var response = client . bulk ( bulkRequest . build () );
67
-
68
- if ( response . errors () ) {
69
- LOGGER .error ("Errors during bulk update." );
71
+ if ( response . errors ()) {
72
+ LOGGER . error ( "Errors during bulk update." );
73
+ }
74
+ } catch ( IOException e ) {
75
+ LOGGER .error ("IO error during bulk update" , e );
70
76
}
71
- } catch (IOException e ) {
72
- LOGGER .error ("IO error during bulk update" , e );
73
- }
74
77
75
- bulkRequest = new BulkRequest .Builder ();
76
- todoDocuments = 0 ;
78
+ bulkRequest = new BulkRequest .Builder ();
79
+ todoDocuments = 0 ;
80
+ }
77
81
}
78
82
}
0 commit comments