Solr 6.2.1-错误的请求(400)-无效的内容类型application / x-www-form-urlencoded; (ManagedSynonymsFilterFactory)

时间:2018-10-17 17:24:34

标签: solr solrj solrcloud solr6

使用以下查询添加新的同义词映射,可以PUT / POST一个映射。 (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"

并得到以下错误响应:

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}}

我正在遵循Solr文档中的示例,但仍然遇到此错误。为什么即使我按照文档中的每个步骤进行操作,也会出现此错误。我在Windows上使用 Solr 6.2.1

上面示例的

文档:https://lucene.apache.org/solr/guide/6_6/managed-resources.html

3 个答案:

答案 0 :(得分:0)

我已经多次看到这样的错误。我现在无法确定正确的问题,但这与Solr无关,而与Curl无关。

当您在Windows中时,我想您正在使用cmd,我强烈建议您设置WSL并在ubuntu(或您喜欢的任何Linux)终端中进行所有卷曲以进行solr,能够使用文档/示例中的所有代码片段而无需将它们转换为Windows world,这将使您的生活变得更加轻松。

答案 1 :(得分:0)

您必须在Windows中cmd下的参数周围使用"",而不是''。要在JSON字符串中转义",请使用"",或将JSON内容添加到文件中并使用-d "@request.json"来避免显式转义任何内容。

答案 2 :(得分:0)

使用以下示例解决您的问题

错误请求: curl -X PUT -H'Content-type:application / json'--data-binary'[“ foo”]'“ http:// localhost:8983 / solr / collection1 / schema / analysis /停用词/ 英语”

正确的请求:curl -X POST -H“ Content-type:application / json” --data-binary“ [” foo“]”“ http:// localhost:8983 / solr / techproducts / schema / analysis / stopwords / english“

注意:在请求中将'简单替换为'即可。