放置请求失败,无法solr

时间:2019-06-10 15:49:52

标签: python json solr

我有一个新的json文件,我想用新的json文件覆盖solr上的功能存储json文件。因此,我编写了以下代码:

filename ='_schema_feature-store.json'

import requests
import json
from requests.auth import HTTPBasicAuth


with open(filename) as json_f:
    solrModel = json.load(json_f)
    url = 'http://xx.xxx.xx.xx:xxxx/solr/someurl/' + "schema/feature-store"
    resp = requests.put(url, json.dumps(solrModel), auth=HTTPBasicAuth('username', 'password'))
    print(resp.text)

当然上面的网址是真实的网址。

但是在发送此请求时,我得到以下响应:

{
  "responseHeader":{
    "status":500,
    "QTime":1174},
  "error":{
    "msg":"ts_title_0 already contained in the store, please use a different name",
    "trace":"org.apache.solr.ltr.feature.FeatureException: ts_title_0 already contained in the store, please use a different name\n\tat org.apache.solr.ltr.store.FeatureStore.add(FeatureStore.java:50)\n\tat org.apache.solr.ltr.store.res\
t.ManagedFeatureStore.addFeature(ManagedFeatureStore.java:122)\n\tat org.apache.solr.ltr.store.rest.ManagedFeatureStore.applyUpdatesToManagedData(ManagedFeatureStore.java:132)\n\tat org.apache.solr.rest.ManagedResource.doPut(ManagedReso\
urce.java:395)\n\tat org.apache.solr.rest.RestManager$ManagedEndpoint.put(RestManager.java:340)\n\tat org.restlet.resource.ServerResource.doHandle(ServerResource.java:447)\n\tat org.restlet.resource.ServerResource.doConditionalHandle(Se\
rverResource.java:359)\n\tat org.restlet.resource.ServerResource.handle(ServerResource.java:1044)\n\tat org.restlet.resource.Finder.handle(Finder.java:236)\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\n\tat org.restlet.rou\
ting.Filter.handle(Filter.java:197)\n\tat org.restlet.routing.Router.doHandle(Router.java:422)\n\tat org.restlet.routing.Router.handle(Router.java:639)\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\n\tat org.restlet.routing\
.Filter.handle(Filter.java:197)\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\n\tat org.restlet.routing.Filter.handle(Filter.java:197)\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\n\tat org.restlet.engine.appl\
ication.StatusFilter.doHandle(StatusFilter.java:140)\n\tat org.restlet.routing.Filter.handle(Filter.java:197)\n\tat org.restlet.routing.Filter.doHandle(Filter.java:150)\n\tat org.restlet.routing.Filter.handle(Filter.java:197)\n\tat org.\
restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)\n\tat org.restlet.engine.application.ApplicationHelper.handle(ApplicationHelper.java:75)\n\tat org.restlet.Application.handle(Application.java:385)\n\tat org.restlet.routin\
g.Filter.doHandle(Filter.java:150)\n\tat org.restlet.routing.Filter.handle(Filter.java:197)\n\tat org.restlet.routing.Router.doHandle(Router.java:422)\n\tat org.restlet.routing.Router.handle(Router.java:639)\n\tat org.restlet.routing.Fi\
lter.doHandle(Filter.java:150)\n\tat org.restlet.routing.Filter.handle(Filter.java:197)\n\tat org.restlet.routing.Router.doHandle(Router.java:422)\n\tat org.restlet.routing.Router.handle(Router.java:639)\n\tat org.restlet.routing.Filter\
.doHandle(Filter.java:150)\n\tat org.restlet.routing.Filter.handle(Filter.java:197)\n\tat org.restlet.engine.CompositeHelper.handle(CompositeHelper.java:202)\n\tat org.restlet.Component.handle(Component.java:408)\n\tat org.restlet.Serve\
r.handle(Server.java:507)\n\tat org.restlet.engine.connector.ServerHelper.handle(ServerHelper.java:63)\n\tat org.restlet.engine.adapter.HttpServerHelper.handle(HttpServerHelper.java:143)\n\tat org.restlet.ext.servlet.ServerServlet.servi\
ce(ServerServlet.java:1117)\n\tat javax.servlet.http.HttpServlet.service(HttpServlet.java:790)\n\tat org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:845)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletH\
andler.java:584)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:566)\n\tat org.eclipse.jetty.server.session.SessionHandler\
.doHandle(SessionHandler.java:226)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)\n\tat org.eclipse.jetty.server.s\
ession.SessionHandler.doScope(SessionHandler.java:185)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat org\
.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:199)\n\tat org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:74)\n\tat org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:356)\n\tat org.apache.\
solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:298)\n\tat org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1691)\n\tat org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.j\
ava:582)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\n\tat org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)\n\tat org.eclipse.jetty.server.session.SessionHandler.doHandl\
e(SessionHandler.java:226)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1180)\n\tat org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:512)\n\tat org.eclipse.jetty.server.session.S\
essionHandler.doScope(SessionHandler.java:185)\n\tat org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1112)\n\tat org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\n\tat org.eclipse\
.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)\n\tat org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.h\
andle(HandlerWrapper.java:134)\n\tat org.eclipse.jetty.rewrite.handler.RewriteHandler.handle(RewriteHandler.java:335)\n\tat org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)\n\tat org.eclipse.jetty.server.S\
erver.handle(Server.java:534)\n\tat org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:320)\n\tat org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)\n\tat org.eclipse.jetty.io.AbstractConnection$ReadCa\
llback.succeeded(AbstractConnection.java:273)\n\tat org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)\n\tat org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)\n\tat org.eclipse.jetty.util.thre\
ad.strategy.ExecuteProduceConsume.executeProduceConsume(ExecuteProduceConsume.java:303)\n\tat org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceConsume(ExecuteProduceConsume.java:148)\n\tat org.eclipse.jetty.util.threa\
d.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:136)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:671)\n\tat org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java\
:589)\n\tat java.lang.Thread.run(Thread.java:748)\n",  ...

,依此类推。我认为错误中最值得注意的部分是:

ts_title_0 already contained in the store

但是,我的新json文件仅包含一个ts_title_0,如下所示:

"name":"ts_title_0",

,这是整个文件中ts_title_0的唯一实例。那为什么会出现这个错误?

1 个答案:

答案 0 :(得分:0)

我认为您应该在request.post中使用更新网址。例如:

url='http://localhost:8983/solr/my_collection/update?commit=true'
payload=open(filename, 'rb').read()
headers={'Content-type':'application/csv'}
response = requests.post(url, auth=('user', 'passwd'), headers=headers, data=payload, timeout=5)`

检出Solr负载测试脚本,在该脚本中我多次更新相同的csv文件: https://github.com/itzmestar/solr/blob/master/solr_post.py

希望这会有所帮助