我在让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')
在底部,但它似乎没有工作。请帮忙吗?