Apache Solr 6.6 replace document instead of update

对着背影说爱祢 提交于 2019-12-11 07:31:03

问题


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)

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?


回答1:


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.

  • Remove the existing document which has the same ID

  • 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=*****)

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

You can probably refer to this similar stackoverflow solution similar answer



来源:https://stackoverflow.com/questions/47257365/apache-solr-6-6-replace-document-instead-of-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!