我在收到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