Upadate document in DocumentProcessor in vespa

80 Views Asked by At

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.

1

There are 1 best solutions below

2
On BEST ANSWER
documentUpdate.addFieldUpdate(FieldUpdate.createAssign(documentUpdate.getDocumentType().getField("myField"),
                                                       new StringFieldValue("myValue")));