Skip to content

Commit 6dad20a

Browse files
committed
Index must be done with PUT, not POST nowadays.
1 parent 7b09b54 commit 6dad20a

File tree

1 file changed

+18
-3
lines changed
  • vpro-shared-elasticsearch-client/src/main/java/nl/vpro/elasticsearchclient

1 file changed

+18
-3
lines changed

vpro-shared-elasticsearch-client/src/main/java/nl/vpro/elasticsearchclient/IndexHelper.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,25 @@ public final ObjectNode post(String path, ObjectNode request, Consumer<Request>.
566566
}
567567

568568
@SafeVarargs
569-
public final ObjectNode postEntity(String path, HttpEntity entity, Consumer<Request>... consumers) {
569+
public final ObjectNode put(String path, ObjectNode request, Consumer<Request>... consumers) {
570+
return putEntity(path, entity(request), consumers);
571+
}
572+
573+
public final ObjectNode postEntity(String path, HttpEntity entity, Consumer<Request>... consumers)
574+
{
575+
return sendEntity(POST, path, entity, consumers);
576+
}
577+
578+
public final ObjectNode putEntity(String path, HttpEntity entity, Consumer<Request>... consumers)
579+
{
580+
return sendEntity(PUT, path, entity, consumers);
581+
}
582+
583+
@SafeVarargs
584+
public final ObjectNode sendEntity(String method, String path, HttpEntity entity, Consumer<Request>... consumers) {
570585
try {
571586

572-
Request req = new Request(POST, path);
587+
Request req = new Request(method, path);
573588
req.setEntity(entity);
574589
for (Consumer<Request> c : consumers) {
575590
c.accept(req);
@@ -679,7 +694,7 @@ public ObjectNode index(String id, byte[] o) {
679694
public ObjectNode index(String id, Object o, Consumer<ObjectNode> sourceConsumer) {
680695
ObjectNode jsonNode = objectMapper.valueToTree(o);
681696
sourceConsumer.accept(jsonNode);
682-
return post(indexPath(id), jsonNode);
697+
return put(indexPath(id), jsonNode);
683698
}
684699

685700

0 commit comments

Comments
 (0)