0

When I execute the code

SolrJsonRequest rq = new SolrJsonRequest(SolrRequest.METHOD.POST, "/config");
String searchComponent = "{\n" +
                "\"add-searchcomponent\":{\n" +
                "    \"name\":\"suggest\",\n" +
                "    \"class\":\"solr.SuggestComponent\",\n" +
                "    \"suggester\":{\n" +
                "        \"name\":\"mySuggester\",\n" +
                "        \"lookupImpl\":\"FuzzyLookupFactory\",\n" +
                "        \"dictionaryImpl\":\"DocumentDictionaryFactory\",\n" +
                "        \"field\":\"suggest\",\n" +
                "        \"suggestAnalyzerFieldType\":\"text_general\"\n" +
                "    }\n" +
                "}\n" +
                "}";

rq.addContentToStream(searchComponent);
rq.process(solrCLient);

I am getting the error

{
  "responseHeader":{
    "status":500,
    "QTime":0},
  "WARNING":"This response format is experimental.  It is likely to change in the future.",
  "error":{
    "msg":"Expected key,value separator ':': char=(EOF),position=363 AFTER=''",
    "trace":"org.noggit.JSONParser$ParseException: Expected key,value separator ':': char=(EOF),position=363 AFTER=''\n\tat org.noggit.JSONParser.err(JSONParser.java:452)\n\tat org.noggit.JSONParser.nextEvent(JSONParser.java:1104)\n\tat org.apache.solr.common.util.CommandOperation.parse(CommandOperation.java:292)\n\tat org.apache.solr.common.util.CommandOperation.readCommands(CommandOperation.java:362)\n\tat ....\n",
    "code":500}}

How to fix it? I need to add a new search component using the API.

If I send same request using RestTemplate everything works fine.

user13674325
  • 339
  • 2
  • 14
  • Look at the actual JSON being sent (a debugger or Wireshark can help you with that); the JSON error is telling you that the JSON the server received can't be parsed properly. That might be caused by the request containing more data than expected. – MatsLindh Aug 24 '20 at 08:17
  • If I send same data with `RestTemplate` everything works, so data should be ok – user13674325 Aug 24 '20 at 08:27
  • Apparently not, since the request fails when parsing the JSON. My point is that the `SolrJsonRequest` seems to behave in a way differently from what you expect (maybe the data is being escaped or it expects a different kind of object as its input, so that it serializes wrong). Look at the raw content being sent to the server, don't dismiss it as being correct when it doesn't do what it should :-) – MatsLindh Aug 24 '20 at 10:01

1 Answers1

0

Could you please try below code?

SolrJsonRequest rq = new SolrJsonRequest(SolrRequest.METHOD.POST, "/config");
String searchComponent = "{\"add-searchcomponent\":{\"name\":\"suggest\",\"class\":\"solr.SuggestComponent\",\"suggester\":{\"name\":\"mySuggester\",\"lookupImpl\":\"FuzzyLookupFactory\",\"dictionaryImpl\":\"DocumentDictionaryFactory\",\"field\":\"suggest\",\"suggestAnalyzerFieldType\":\"text_general\"}}}";

rq.addContentToStream(searchComponent);
rq.process(solrCLient);
Abhijit Bashetti
  • 8,518
  • 7
  • 35
  • 47
  • try by passing the json to StringEntity StringEntity entity = new StringEntity("yourJson", "UTF-8"); entity.setContentType("application/json"); – Abhijit Bashetti Aug 24 '20 at 05:41
  • I am getting the error `java.lang.IllegalArgumentException: No serializer found for class java.io.ByteArrayInputStream and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) (through reference chain: org.apache.http.entity.StringEntity["content"])` – user13674325 Aug 24 '20 at 06:11