Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nested atomic updates to non-existent child docs #70

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@
public class AtomicUpdateDocumentMerger {

private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());


protected final SolrQueryRequest request;
protected final IndexSchema schema;
protected final SchemaField idField;

public AtomicUpdateDocumentMerger(SolrQueryRequest queryReq) {
request = queryReq;
schema = queryReq.getSchema();
idField = schema.getUniqueKeyField();
}
Expand Down Expand Up @@ -485,12 +487,16 @@ private void doAddChildren(
+ existingField.getName()
+ " since it contains values which are either not SolrInputDocument's or do not have an id property");
}
boolean skipMissingChildren = request.getParams().getBool("skipUpdateIfMissing", false);
for (SolrInputDocument child : children) {
if (isAtomicUpdate(child)) {
// When it is atomic update, update the nested document ONLY if it already exists
final BytesRef childIdBytes = readChildIdBytes(child);
SolrInputDocument original = originalChildrenById.get(childIdBytes);
if (original == null) {
if (skipMissingChildren) {
continue;
}
throw new SolrException(
ErrorCode.BAD_REQUEST,
"A nested atomic update can only update an existing nested document");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ public void testAtomicUpdateNonExistingChildException() throws Exception {
docMerger.merge(updateDoc, existingDoc);
});
assertTrue(expected.getMessage().equals("A nested atomic update can only update an existing nested document"));

AtomicUpdateDocumentMerger docMergerSkipMissing = new AtomicUpdateDocumentMerger(req("skipUpdateIfMissing", "true"));
docMergerSkipMissing.merge(updateDoc, existingDoc); // no exception due to extra param
assertEquals(1, existingDoc.getFieldValues("child_ss").size());
}

@Test
Expand Down
Loading