2016-06-08 34 views
0

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

在底部,但它似乎並不奏效。請幫助?

+0

你能看到Solr日誌中的提交請求嗎?還有,嘗試在提交調用中添加'openSearcher = True',以便您的客戶端將等待提交的數據實際可搜索。 – MatsLindh

回答

0

的承諾庫的函數設置參數如下:

openSearcher=False 
softCommit=False 
waitSearcher=True 
commit=True 

自硬提交和OpenSearch的是假的,高速緩存未失效,因此你無法看到新添加的記錄。你可以參考herehere

所以你可以根據用例來決定你想要的提交類型並相應地設置它們。我希望這有幫助。

+0

感謝您解釋這一點。我會在下班後檢查,然後給你接受,如果這結束了工作。 – Zack

相關問題