从solr删除所有文件
curl http://localhost:8983/solr/trans/update?commit=true -d "<delete><query>*:*</query></delete>"
向架构添加(静态)属性是
curl -X POST -H 'Content-type:application/json' --data-binary '{ "add-field":{"name":"trans","type":"string","stored":true, "indexed":true},}' http://localhost:8983/solr/trans/schema
删除一个属性是
curl -X POST -H 'Content-type:application/json' -d '{ "delete-field":{"name":"trans"}}' http://arteika:8983/solr/trans/schema
有没有办法从架构中删除所有属性?
答案 0 :(得分:0)
至少在Schema API的6.6版和最新的7.5版中,您可以在单个帖子中传递多个命令(分别参见6.6和7.5文档)。接受的格式有多种,但最直观的格式(我认为)只是传递要执行的操作的数组:
curl -X POST -H 'Content-type: application/json' -d '{
"delete-field": [
{"name": "trans"},
{"name": "other_field"}
]
}' 'http://arteika:8983/solr/trans/schema'
所以。我们如何获取要删除的字段的名称?可以通过查询模式来完成:
curl -X GET -H 'Content-type: application/json' 'http://arteika:8983/solr/trans/schema'
特别是,响应中copyFields
对象中的dynamicFields
,fields
和schema
键。
我自动清除所有副本字段规则,动态字段规则和字段,如下所示。当然,您可以使用任何可用的脚本。我使用了Python 3(可以与Python 2一起使用,但我没有对其进行测试)。
import json
import requests
# load schema information
api = 'http://arteika:8983/solr/trans/schema'
r = requests.get(api)
# delete copy field rules
names = [(o['source'], o['dest']) for o in r.json()['schema']['copyFields']]
payload = {'delete-copy-field': [{'source': name[0], 'dest': name[1]} for name in names]}
requests.post(api, data = json.dumps(payload),
headers = {'Content-type': 'application/json'})
# delete dynamic fields
names = [o['name'] for o in r.json()['schema']['dynamicFields']]
payload = {'delete-dynamic-field': [{'name': name} for name in names]}
requests.post(api, data = json.dumps(payload),
headers = {'Content-type': 'application/json'})
# delete fields
names = [o['name'] for o in r.json()['schema']['fields']]
payload = {'delete-field': [{'name': name} for name in names]}
requests.post(api, data = json.dumps(payload),
headers = {'Content-type': 'application/json'})
仅需注意:我最初收到状态为400的响应,并带有null
错误消息。在弄清楚如何解决这些问题上有些困难,所以我要分享对我有用的东西。将updateRequestProcessorChain
中的solrconfig.xml
的默认值更改为false
(default="${update.autoCreateFields:false}"
)并重新启动Solr服务,这些错误对我来说就消失了。我要删除的字段是自动创建的,可能与此有关。