2016-06-08 89 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

相关问题