SolrClient在重新启动solr进程之前不会提交更改

时间:2016-06-08 01:40:18

标签: python solr client commit restart

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

在底部,但它似乎没有工作。请帮忙吗?

1 个答案:

答案 0 :(得分:0)

库的提交功能设置参数如下:

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

由于其硬提交且openSearch为false,因此缓存不会失效,因此您无法看到新添加的记录。您可以参考herehere

因此,您可以根据用例决定所需的提交类型并相应地进行设置。我希望这会有所帮助。