Thakur Sahab
Thakur Sahab

Reputation: 65

Solr 6.2.1 - Bad Request (400) - Invalid content type application/x-www-form-urlencoded; (ManagedSynonymsFilterFactory)

Using following query to add a new synonym mapping, you can PUT/POST a single mapping. (ManagedSynonymFilterFactory)

curl -X PUT -H 'Content-type:application/json' --data-binary 
'{"mad":["angry","upset"], "happy": ["smiling", "jolly"]}' 
"localhost:8983/solr/techproducts/schema/analysis/synonyms/english"

and getting the following response with error:

curl: (6) Could not resolve host: happy
curl: (3) [globbing] bad range in column 2
curl: (3) [globbing] unmatched close brace/bracket in column 6
{
"responseHeader":{
"status":500,
"QTime":111},
"error":{
"msg":"Bad Request",
"trace":"Bad Request (400) - Invalid content type application/x-www-form- 
urlencoded; only application/json is supported.\r\n\tat only application/json is supported.\r\n\tat org.apache.solr.rest.RestManager$ManagedEndpoint.parseJsonFromRequestBody(RestManager.java:407)\r\n\tat 
org.apache.solr.rest.RestManager$ManagedEndpoint.put(RestManager.java:340)\r\n\tat org.restlet.resource.ServerResource.doHandle(ServerResource.java:447)\r\n\tat 
org.restlet.resource.ServerResource.doConditionalHandle(ServerResource.java:359)\r\n\tat org.restlet.resource.ServerResource.handle(ServerResource.java:1044)\r\n\tat 
org.restlet.resource.Finder.handle(Finder.java:236)\r\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\r\n\tat 
org.restlet.routing.Filter.handle(Filter.java:197)\r\n\tat org.restlet.routing.Router.doHandle(Router.java:422)\r\n\tat 
org.restlet.routing.Router.handle(Router.java:639)\r\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\r\n\tat 
org.restlet.routing.Filter.handle(Filter.java:197)\r\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\r\n\tat 
org.restlet.routing.Filter.handle(Filter.java:197)\r\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\r\n\tat 
org.restlet.engine.application.StatusFilter.doHandle(StatusFilter.java:140)\r\n\tat org.restlet.routing.Filter.handle(Filter.java:197)\r\n\tat 
org.restlet.routing.Filter.doHandle(Filter.java:150)\r\n\tat org.restlet.routing.Filter.handle(Filter.java:197)\r\n\tat 
org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)\r\n\tat org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.java:75)\r\n\tat 
org.restlet.Application.handle(Application.java:385)\r\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\r\n\tat 
org.restlet.routing.Filter.handle(Filter.java:197)\r\n\tat org.restlet.routing.Router.doHandle(Router.java:422)\r\n\tat org.restlet.routing.Router.handle(Router.java:639)\r\n\tat 
org.restlet.routing.Filter.doHandle(Filter.java:150)\r\n\tat org.restlet.routing.Filter.handle(Filter.java:197)\r\n\tat 
org.restlet.routing.Router.doHandle(Router.java:422)\r\n\tat org.restlet.routing.Router.handle(Router.java:639)\r\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\r\n\tat 
org.restlet.routing.Filter.handle(Filter.java:197)\r\n\tat org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)\r\n\tat 
org.restlet.Component.handle(Component.java:408)\r\n\tat org.restlet.Server.handle(Server.java:507)\r\n\tat 
org.restlet.engine.connector.ServerHelper.handle(ServerHelper.java:63)\r\n\tat org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:143)\r\n\tat 
org.restlet.ext.servlet.ServerServlet.service(ServerServlet.java:1117)\r\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:790)\r\n\tat 
org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583)\r\n\tat 
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\r\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:566)\r\n\tat 
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)\r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1160)\r\n\tat 
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)\r\n\tat 
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1092)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\r\n\tat 
org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:199)\r\n\tat org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:74)\r\n\tat 
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:266)\r\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:208)\r\n\tat 
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1668)\r\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)\r\n\tat 
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\r\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)\r\n\tat 
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)\r\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1160)\r\n\tat 
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)\r\n\tat org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)\r\n\tat 
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1092)\r\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\r\n\tat 
org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)\r\n\tat 
org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)\r\n\tat 
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)\r\n\tat org.eclipse.jetty.server.Server.handle(Server.java:518)\r\n\tat 
org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)\r\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)\r\n\tat 
org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)\r\n\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)\r\n\tat 
org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)\r\n\tat 
org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:246)\r\n\tat 
org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:156)\r\n\tat 
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)\r\n\tat 
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)\r\n\tat java.lang.Thread.run(Unknown Source)\r\n",
"code":500}}

I was following an example in Solr document but still got this error. Why this error occured even when I'm following each step from the doc. I'm using Solr 6.2.1 on Windows

document for above example: https://lucene.apache.org/solr/guide/6_6/managed-resources.html

Upvotes: 0

Views: 1138

Answers (3)

Thrivikram M
Thrivikram M

Reputation: 11

Solve your problem with the below example

Error Request: curl -X PUT -H 'Content-type:application/json' --data-binary '["foo"]' "http://localhost:8983/solr/collection1/schema/analysis/stopwords/ english"

Correct Request: curl -X POST -H "Content-type:application/json" --data-binary "["foo"]" "http://localhost:8983/solr/techproducts/schema/analysis/stopwords/english"

Note: Simple replace ' with " in the request to make it simple.

Upvotes: 0

MatsLindh
MatsLindh

Reputation: 52912

You have to use "" around parameters under cmd in Windows, not ''. To escape the " inside the JSON string, use "", or add the JSON content to a file and use -d "@request.json" instead, avoiding the need to escape anything explicitly.

Upvotes: 0

Persimmonium
Persimmonium

Reputation: 15789

I have seen such errors many times. I cannot pinpoint the right issue right now, but it has nothing to do with Solr, but with Curl.

As you are in windows, I guess you are using cmd, I strongly advise you set up WSL and do all curl-ing to solr in a ubuntu (or whatever linux you prefer) terminal, you will be able to use all snippets from the doc/examples without converting them to Windows world, and your life will be much easier.

Upvotes: 0

Related Questions