Apache Solr open-source search software
SOLR-1695: Added an earlier check for multiple values being used in the uniqueKey field - prior to this the only check was done in the UpdateHandler (IndexSchema logs an erro if the field is declared multiValued=true, but it's not considered fatal since it will still work as long as clients only send one value)
Chris M. Hostetter95480576eb97
diff --git a/CHANGES.txt b/CHANGES.txtindex e1f443e8d51..b63a60c2e18 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -242,8 +242,8 @@ Other Changes* SOLR-1771: Improved error message when StringIndex cannot be initializedfor a function query (hossman)-* SOLR-1695: Improved error message when adding a document that does not- contain a value for the uniqueKey field (hossman)+* SOLR-1695: Improved error messages when adding a document that does not+ contain exactly one value for the uniqueKey field (hossman)Build----------------------diff --git a/src/java/org/apache/solr/update/DocumentBuilder.java b/src/java/org/apache/solr/update/DocumentBuilder.javaindex c6eaeba798d..8113389d5ce 100644--- a/src/java/org/apache/solr/update/DocumentBuilder.java+++ b/src/java/org/apache/solr/update/DocumentBuilder.java@@ -232,9 +232,15 @@ public class DocumentBuilder {Collection<Object> keys = doc.getFieldValues(uniqueKeyField.getName());if (null == keys || keys.isEmpty()) {throw new SolrException(SolrException.ErrorCode.BAD_REQUEST,- "Document missing value for uniqueKeyField: " ++ "Document missing a value for uniqueKey field: " +uniqueKeyField.getName());}+ if (1 < keys.size()) {+ throw new SolrException+ (SolrException.ErrorCode.BAD_REQUEST,+ "Document contains multiple values for uniqueKey field: " ++ uniqueKeyField.getName());+ }}// Load fields from SolrDocument to Document