首页 > 解决方案 > Solr:删除id中带有尖括号的文档

问题描述

我正在尝试从 Solr 索引中删除文档。我正在使用 pysolr 并尝试通过 id 和查询删除它们。在这两种情况下,操作都会失败,并带有如下 ID:cr-10.1002/(sici)1520-6688(199621)15:2<476::aid-pam7>3.3.co;2-2出现以下错误:

pysolr.SolrError: Solr responded with an error (HTTP 400): [Reason: Unexpected character '4' (code 52) in content after '<' (malformed start element?). at [row,col {unknown-source}]: [1,53]]

https://lucene.apache.org/core/7_2_1/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#Escaping_Special_Characters根本没有提到转义尖括号。我试过了,但没有运气。

知道我可以做些什么来删除这些文件吗?

编辑:更新了 ID 以匹配错误

标签: pythonsolrlucene

解决方案


我最终使用了这样的 JSON API:

import requests

url = 'http://localhost:8983/solr/collection/update' # update endpoint of the collection

ids_to_delete = ['a', 'b<c', 'd:e']
requests.post(url, json={ 'delete': ids_to_delete })

推荐阅读