Skip to content

Commit 4c57206

Browse files
committed
support for routing list in bulk op
1 parent ca2c057 commit 4c57206

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

java-client/src/main/java/co/elastic/clients/elasticsearch/_helpers/bulk/IngesterOperation.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import co.elastic.clients.util.BinaryData;
3131

3232
import javax.annotation.Nullable;
33+
import java.util.List;
3334

3435
/**
3536
* A bulk operation whose size has been calculated and content turned to a binary blob (to compute its size).
@@ -212,6 +213,23 @@ private static int size(String name, @Nullable JsonEnum value) {
212213
}
213214
}
214215

216+
private static int size(String name, @Nullable List<String> value) {
217+
if (value != null) {
218+
if (value.isEmpty()) {
219+
return name.length() + 6; // 6 added chars for empty array "name":[],
220+
}
221+
int listSize = 0;
222+
for (String item : value) {
223+
listSize += item.length();
224+
listSize += 2; // +2 quotes each item
225+
}
226+
listSize += value.size()-1 ; // +1 comma between each item
227+
return name.length() + listSize + 6; // "name":["item1","item2","item3"],
228+
} else {
229+
return 0;
230+
}
231+
}
232+
215233
private static int basePropertiesSize(BulkOperationBase op) {
216234
return
217235
size("id", op.id()) +

java-client/src/test/java/co/elastic/clients/elasticsearch/_helpers/bulk/BulkIngesterTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public void beforeBulk(long executionId, BulkRequest request, List<Void> context
418418
.listener(listener)
419419
.globalSettings(s -> s
420420
.index("foo")
421-
.routing("bar")
421+
.routing("bar","aaa")
422422
)
423423
);
424424

@@ -431,7 +431,8 @@ public void beforeBulk(long executionId, BulkRequest request, List<Void> context
431431
assertEquals(1, ingester.requestCount());
432432

433433
assertEquals("foo", storedRequest.get().index());
434-
assertEquals("bar", storedRequest.get().routing());
434+
assertEquals("bar", storedRequest.get().routing().get(0));
435+
assertEquals("aaa", storedRequest.get().routing().get(1));
435436
}
436437

437438
@Test

0 commit comments

Comments
 (0)