Reputation: 371
How to add new field to existing document in DocumentProcessor when updating document using REST API.
@Override
public Progress process(Processing processing) {
for (DocumentOperation op : processing.getDocumentOperations()) {
if (op instanceof DocumentUpdate) {
DocumentUpdate documentUpdate = (DocumentUpdate) op;
// what shoud I write here to add new field with value
}
}
return Progress.DONE;
}
When I am using code below, this gives me error
DocumentUpdate upd = new DocumentUpdate(type, id);
upd.addFieldUpdate(FieldUpdate.createMap(type.getField("myStrWSet"), "foo", new AssignValueUpdate(100)));
Error : AssignValueUpdate cannot be applies to int.
And, how to create FieldUpdate object with new field and its value.
Please help.
Upvotes: 1
Views: 79
Reputation: 2339
documentUpdate.addFieldUpdate(FieldUpdate.createAssign(documentUpdate.getDocumentType().getField("myField"),
new StringFieldValue("myValue")));
Upvotes: 3