【问题标题】:indexing data to solr update url from python code in json format does not update the record in solr从 json 格式的 python 代码将数据索引到 solr 更新 url 不会更新 solr 中的记录
【发布时间】:2015-10-14 09:23:17
【问题描述】:

我正在使用 python 函数将数据索引到本地主机上的 solr 我的代码如下

import urllib
import urllib2

def indexSolrVenue():
    url = 'http://localhost:8983/solr/venue/update/json?commit=true&wt=json'
    data = '[{"id":"3","title":"allen"}]'
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req)
    the_page = response.read()
    print the_page

在 solr 中,我定义了一个接受 id 和标题的模式。我尝试使用 postman chrome 扩展将数据发送到 url

http://localhost:8983/solr/venue/update/json?commit=true

有数据

[{'id':'2','title':'test1'}]

它被正确索引并反映在 solr 中。但是如果我在终端上运行 python 代码,我会得到以下输出

{"responseHeader":{"status":0,"QTime":6}}

这实际上意味着当我尝试使用 : query

搜索数据时,数据正在被索引但在 solr 上
http://localhost:8983/solr/venue/select?q=*%3A*&wt=json&indent=true

它没有显示 id:3 记录。

我在我的代码中做错了吗?请帮忙 提前谢谢

【问题讨论】:

    标签: python json solr lucene


    【解决方案1】:
    req.add_header('Content-type', 'application/json')
    

    您需要为您的 req 对象中的内容设置标题。请在调用urllib2.urlopen(req)之前使用上述语句;

    【讨论】:

      猜你喜欢
      • 2014-08-04
      • 2012-01-25
      • 1970-01-01
      • 2011-06-17
      • 2012-06-15
      • 1970-01-01
      • 2011-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多