@@ -67,6 +67,8 @@ public class StandardSink<C extends StandardContext> implements Sink<C> {
67
67
protected String type ;
68
68
69
69
protected String id ;
70
+
71
+ protected boolean docAsUpsert ;
70
72
71
73
private final static SinkMetric sinkMetric = new SinkMetric ().start ();
72
74
@@ -96,6 +98,7 @@ public synchronized void beforeFetch() throws IOException {
96
98
Settings settings = context .getSettings ();
97
99
String index = settings .get ("index" , "jdbc" );
98
100
String type = settings .get ("type" , "jdbc" );
101
+ this .docAsUpsert = settings .getAsBoolean ("docAsUpsert" , false );
99
102
if (clientAPI == null ) {
100
103
clientAPI = createClient (settings );
101
104
if (clientAPI .client () != null ) {
@@ -276,10 +279,11 @@ public void update(IndexableObject object) throws IOException {
276
279
setId (object .id ());
277
280
}
278
281
if (getId () == null ) {
279
- return ; // skip if no doc is specified to delete
282
+ return ; // skip if no doc is specified to update
280
283
}
281
284
UpdateRequest request = new UpdateRequest ().index (this .index ).type (this .type ).id (getId ()).doc (object .source ());
282
- request .docAsUpsert (true );
285
+ if (this .docAsUpsert )
286
+ request .docAsUpsert (true );
283
287
284
288
if (object .meta (ControlKeys ._version .name ()) != null ) {
285
289
request .versionType (VersionType .EXTERNAL )
@@ -292,7 +296,7 @@ public void update(IndexableObject object) throws IOException {
292
296
request .parent (object .meta (ControlKeys ._parent .name ()));
293
297
}
294
298
if (logger .isTraceEnabled ()) {
295
- logger .trace ("adding bulk update action {}/{}/{}" , request .index (), request .type (), request .id ());
299
+ logger .trace ("adding bulk update action {}/{}/{} docAsUpsert {} " , request .index (), request .type (), request .id (), this . docAsUpsert );
296
300
}
297
301
clientAPI .bulkUpdate (request );
298
302
}
0 commit comments