Created
October 6, 2019 17:36
-
-
Save epifanio/0f92c920a5a97677e1134da1c3a51ebb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import json\n", | |
"import requests\n", | |
"import time" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# the file below is generated from a curl request to the met solr istance\n", | |
"#\n", | |
"# e.g.: !curl http://host:port/solr/core_name/schema?wt=json\n", | |
"#\n", | |
"!gist ../dev/dataset-search-services/schema.json" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"with open('../dev/dataset-search-services/schema.json') as json_file:\n", | |
" data = json.load(json_file)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# constants" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"endopint = 'http://10.0.0.178:8983/solr/met/schema'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"headers = {\n", | |
" 'Content-type': 'application/json',\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Add new Field Types" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"\n", | |
"for i in data['schema']['fieldTypes']:\n", | |
" field_type = {}\n", | |
" field_type['add-field-type'] = i\n", | |
" result = {'headers': headers, 'data': json.dumps(field_type)}\n", | |
" response = requests.post(endopint, \n", | |
" headers=result['headers'], \n", | |
" data=result['data'])\n", | |
" print(i['name'], 'status:', response)\n", | |
" time.sleep(0.2)\n", | |
"\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Add new Fields" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for i in data['schema']['fields']:\n", | |
" field = {}\n", | |
" field['add-field'] = i\n", | |
" result = {'headers': headers, 'data': json.dumps(field)}\n", | |
" response = requests.post(endopint, \n", | |
" headers=result['headers'], \n", | |
" data=result['data'])\n", | |
" print(i['name'], 'status:', response)\n", | |
" time.sleep(0.2)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Add new dynamicFields" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for i in data['schema']['dynamicFields']:\n", | |
" dynamic_field = {}\n", | |
" dynamic_field['add-dynamic-field'] = i\n", | |
" result = {'headers': headers, 'data': json.dumps(dynamic_field)}\n", | |
" response = requests.post(endopint, \n", | |
" headers=result['headers'], \n", | |
" data=result['data'])\n", | |
" print(i['name'], 'status:', response)\n", | |
" time.sleep(0.2)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Add New Copy Field Rule" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for i in data['schema']['copyFields']:\n", | |
" copy_field = {}\n", | |
" copy_field['add-copy-field'] = i\n", | |
" result = {'headers': headers, 'data': json.dumps(copy_field)}\n", | |
" response = requests.post(endopint, \n", | |
" headers=result['headers'], \n", | |
" data=result['data'])\n", | |
" print(i['source'], 'status:', response)\n", | |
" time.sleep(0.2)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"!curl http://10.0.0.178:8983/solr/mmd/schema?wt=json" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.5rc1" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment