Skip to content

Apache Lucene open-source search software

SOLR-6437: Managed schema is not enabled with /update/json and /update/json/docs request handlers

Shalin Shekhar Mangar6f1c5de38f7f
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index b300a7061b1..8132c51dca7 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -227,7 +227,7 @@ New Features
a UUID into the unique Key field.
(Vitaliy Zhovtyuk, hossman, Steve Rowe, Erik Hatcher, shalin)
-* SOLR-6294: Remove the restriction of adding json by only wrapping it in an array in a
+* SOLR-6294: SOLR-6437: Remove the restriction of adding json by only wrapping it in an array in a
new path /update/json/docs (Noble Paul , hossman, Yonik Seeley, Steve Rowe)
* SOLR-6302: UpdateRequestHandlers are registered implicitly /update ,
diff --git a/solr/example/example-schemaless/solr/collection1/conf/solrconfig.xml b/solr/example/example-schemaless/solr/collection1/conf/solrconfig.xml
index 56481ae03f8..d46d778a450 100755
--- a/solr/example/example-schemaless/solr/collection1/conf/solrconfig.xml
+++ b/solr/example/example-schemaless/solr/collection1/conf/solrconfig.xml
@@ -1001,6 +1001,29 @@
</lst>
</requestHandler>
+ <requestHandler name="/update/json" class="solr.UpdateRequestHandler">
+ <!-- See below for information on defining
+ updateRequestProcessorChains that can be used by name
+ on each Update Request
+ -->
+ <lst name="defaults">
+ <str name="update.contentType">application/json</str>
+ <str name="update.chain">add-unknown-fields-to-the-schema</str>
+ </lst>
+ </requestHandler>
+
+ <requestHandler name="/update/json/docs" class="solr.UpdateRequestHandler">
+ <!-- See below for information on defining
+ updateRequestProcessorChains that can be used by name
+ on each Update Request
+ -->
+ <lst name="defaults">
+ <str name="update.contentType">application/json</str>
+ <str name="update.chain">add-unknown-fields-to-the-schema</str>
+ <bool name="json.command">false</bool>
+ </lst>
+ </requestHandler>
+
<!-- Solr Cell Update Request Handler
http://wiki.apache.org/solr/ExtractingRequestHandler
diff --git a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTests.java b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTests.java
index b674285ce35..c062459d878 100644
--- a/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTests.java
+++ b/solr/solrj/src/test/org/apache/solr/client/solrj/SolrSchemalessExampleTests.java
@@ -17,14 +17,22 @@
package org.apache.solr.client.solrj;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.InputStreamEntity;
import org.apache.solr.client.solrj.impl.BinaryRequestWriter;
import org.apache.solr.client.solrj.impl.BinaryResponseParser;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
+import org.apache.solr.client.solrj.request.UpdateRequest;
import org.apache.solr.util.ExternalPaths;
import org.junit.BeforeClass;
+import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.ByteArrayInputStream;
+
public class SolrSchemalessExampleTests extends SolrExampleTestsBase {
private static Logger log = LoggerFactory
.getLogger(SolrSchemalessExampleTests.class);
@@ -33,7 +41,27 @@ public class SolrSchemalessExampleTests extends SolrExampleTestsBase {
public static void beforeTest() throws Exception {
createJetty(ExternalPaths.EXAMPLE_SCHEMALESS_HOME, null, null);
}
-
+
+ @Test
+ public void testArbitraryJsonIndexing() throws Exception {
+ HttpSolrServer server = (HttpSolrServer) getSolrServer();
+ server.deleteByQuery("*:*");
+ server.commit();
+ assertNumFound("*:*", 0); // make sure it got in
+
+ // two docs, one with uniqueKey, another without it
+ String json = "{\"id\":\"abc1\", \"name\": \"name1\"} {\"name\" : \"name2\"}";
+ HttpClient httpClient = server.getHttpClient();
+ HttpPost post = new HttpPost(server.getBaseURL() + "/update/json/docs");
+ post.setHeader("Content-Type", "application/json");
+ post.setEntity(new InputStreamEntity(new ByteArrayInputStream(json.getBytes("UTF-8")), -1));
+ HttpResponse response = httpClient.execute(post);
+ assertEquals(200, response.getStatusLine().getStatusCode());
+ server.commit();
+ assertNumFound("*:*", 2);
+ }
+
+
@Override
public SolrServer createNewSolrServer() {
try {