pysolr更新文件有错误
pysolr update document with error
更新: Pysolr 版本:3.2.0
这似乎是 solr 中的一个错误。当一个操作什么都不更新时,它会删除这个文档。
之前我使用了using pysolr in atomic update中的代码,但是我在下面的情况下出错了。
现在的文档架构可能是这样的:
doc = {
'id': ...,
'title': ...,
'body': ...,
}
我已经为一批文档编制了索引,现在我想用新字段更新每个文档 anchor_text。这是我的代码:
solr = pysolr.Solr(url_solr)
doc_update = {
'id': ...,
'anchor_text': [a,b,c,...]
}
solr.add([doc_update], fieldUpdates={
'anchor_text': 'set'
})
但我发现一些原始文档被删除,只剩下 id 字段。
更新后是这样的:
doc = {
'id':...
}
特别是对于那些anchor_text字段为空列表的,原始文档将被删除。而其他人则不是。(可能我猜是因为我只看到几个案例)。
我查看了源代码,但没有发现任何有价值的东西。这是怎么回事?
更新文档中pysolr的正确使用方法是什么?
我遇到了同样的问题(python-3.6、pysolr-3.6、solr 6.4.1)。由于我在网上找不到更多信息,所以我使用了一个请求解决方法,我会把它留在这里以防它对任何人有用。
import requests
import json
def update_single_solr_field(doc_id_field, doc_id, field_update_name, field_update_value):
# Updates a single field in a document with id 'doc_id'.
# Updates only the 'field_update_name' field to the 'field_update_value', leaving other fields intact
base_url = 'http://localhost:8983/'
solr_url = 'solr/mysolrcore/'
update_url = 'update?commit=true'
full_url = base_url + solr_url + update_url
headers = {'content-type': "application/json"}
payload = [{
doc_id_field: doc_id,
field_update_name: {
'set': field_update_value
}
}]
response = requests.post(full_url, data=json.dumps(payload), headers=headers)
return response
# example
id_field_name = 'id'
doc_id_to_update = '1700370208'
field_to_update = 'weight_field'
field_to_update_value = 20000
response_update = update_single_solr_field(id_field_name, doc_id_to_update, field_to_update, field_to_update_value)
print(response_update)
更新: Pysolr 版本:3.2.0
这似乎是 solr 中的一个错误。当一个操作什么都不更新时,它会删除这个文档。
之前我使用了using pysolr in atomic update中的代码,但是我在下面的情况下出错了。
现在的文档架构可能是这样的:
doc = {
'id': ...,
'title': ...,
'body': ...,
}
我已经为一批文档编制了索引,现在我想用新字段更新每个文档 anchor_text。这是我的代码:
solr = pysolr.Solr(url_solr)
doc_update = {
'id': ...,
'anchor_text': [a,b,c,...]
}
solr.add([doc_update], fieldUpdates={
'anchor_text': 'set'
})
但我发现一些原始文档被删除,只剩下 id 字段。 更新后是这样的:
doc = {
'id':...
}
特别是对于那些anchor_text字段为空列表的,原始文档将被删除。而其他人则不是。(可能我猜是因为我只看到几个案例)。
我查看了源代码,但没有发现任何有价值的东西。这是怎么回事?
更新文档中pysolr的正确使用方法是什么?
我遇到了同样的问题(python-3.6、pysolr-3.6、solr 6.4.1)。由于我在网上找不到更多信息,所以我使用了一个请求解决方法,我会把它留在这里以防它对任何人有用。
import requests
import json
def update_single_solr_field(doc_id_field, doc_id, field_update_name, field_update_value):
# Updates a single field in a document with id 'doc_id'.
# Updates only the 'field_update_name' field to the 'field_update_value', leaving other fields intact
base_url = 'http://localhost:8983/'
solr_url = 'solr/mysolrcore/'
update_url = 'update?commit=true'
full_url = base_url + solr_url + update_url
headers = {'content-type': "application/json"}
payload = [{
doc_id_field: doc_id,
field_update_name: {
'set': field_update_value
}
}]
response = requests.post(full_url, data=json.dumps(payload), headers=headers)
return response
# example
id_field_name = 'id'
doc_id_to_update = '1700370208'
field_to_update = 'weight_field'
field_to_update_value = 20000
response_update = update_single_solr_field(id_field_name, doc_id_to_update, field_to_update, field_to_update_value)
print(response_update)