Apache Solr 6.6替换文档而不是更新 [英] Apache Solr 6.6 replace document instead of update

查看:93
本文介绍了Apache Solr 6.6替换文档而不是更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为测试设置配置了solr 6.6.1.在为几个文档建立索引之后,我必须更新几个字段.我正在使用 solr 的python客户端.要更新,以下是我的代码段

I have configured solr 6.6.1 for a testing setup. After indexing few documents, I have to update few fields. I am using python client of solr. To update, following is my code snippet

import solr

def update_solr_index(_id, _value):
    print solr_conn2.add( id = _id, group2 = _value)

core_ulr = "http://localhost:8983/solr/use"
solr_conn2 = solr.SolrConnection(core_ulr)
update_solr_index(doc_id, field_value)

执行(和提交)后,所有其他字段将从所有文档中删除,仅剩下两个字段doc_id和group2.这个API或我的代码有什么问题?

After execution (and commit), all other fields are removed from all documents and only two fields left that are doc_id and group2. What is the problem is this API or in my code?

推荐答案

API中没有问题.您要solr添加一个文档,该文档的ID字段已经存在于您的收藏夹中. solr中发生以下动作.

There is no problem in the API. You are asking solr to add a document with an ID field that is already present in your collection. The following actions happen in solr.

  • 删除具有相同ID的现有文档

  • Remove the existing document which has the same ID

仅使用该API调用中指定的字段添加新文档

Add new document with only the fields specified in that API call

您正在寻找的解决方案是文档的部分更新.

The solution you are looking for is a partial update of a document.

请参阅参考链接以详细了解原子更新

Refer to the reference link to understand more on this Atomic updates

您需要为要在文档中更新的字段发送地图对象.

You need to send a map object for the field you want to update in your document.

solr_conn2.add(id=_id, group2=*****)

group2的值必须是这样的映射{{set':'value ...'}

The value to group2 must be a map like this {'set':'value...'}

您可能可以参考类似的stackoverflow解决方案类似的答案

You can probably refer to this similar stackoverflow solution similar answer

这篇关于Apache Solr 6.6替换文档而不是更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆