我在收到SolrClient以立即反映我正在做出的更改时遇到了一些麻烦。如果我写入索引,我需要先重新启动正在运行的solr进程,然后才能看到我正在编写的更改。下面是我使用SolrClient没有提交更改,直到重新启动solr进程
import json
from SolrClient import SolrClient
def read_all():
client = SolrClient('http://localhost:8983/solr')
res = client.query('test', {
'q' : '*:*'
})
res = json.loads(res.get_json())
docs = res['response']['docs']
for doc in docs:
print (doc)
def index_json():
client = SolrClient('http://localhost:8983/solr')
docs = [
{'id' : '8', 'field8' : 'value8'},
]
client.index_json('test', json.dumps(docs))
client.commit('test')
因此,代码,假装我已经索引字段1-7,然后我跑我read_all功能。我会看到打印出的文档1-7。然后我运行index_json索引doc 8.如果我再次运行read_all,我只会看到1-7打印出来。我需要运行solr stop,然后solr启动。只有这样我才能看到打印的文档1-8。
我读,我需要提交我的变化,这是一个类似的探测后,为什么我添加
client.commit('test')
在底部,但它似乎并不奏效。请帮助?
你能看到Solr日志中的提交请求吗?还有,尝试在提交调用中添加'openSearcher = True',以便您的客户端将等待提交的数据实际可搜索。 – MatsLindh