Skip to content

Instantly share code, notes, and snippets.

@brandomr
Created November 21, 2022 19:32
Show Gist options
  • Save brandomr/2d720e3a14fe8126dae95523793727ec to your computer and use it in GitHub Desktop.
Save brandomr/2d720e3a14fe8126dae95523793727ec to your computer and use it in GitHub Desktop.
es-mapping-update
from elasticsearch import Elasticsearch
import json
es = Elasticsearch('http://localhost:9200')
q = {
"query": {
"match_all": {}
}
}
indicators = es.search(index='indicators', query=q, size=1000)
indicators = [i.get('_source') for i in indicators['hits']['hits']]
with open('indicators_backup.jsonl','a') as f:
for i in indicators:
f.write(json.dumps(i)+'\n')
# get mapping and fix it
mapping = es.indices.get_mapping('indicators')
mapping['mapping'][...]['outputs'] = 'nested'
# delete the index
es.indices.delete('indicators')
# create the index
# put the updated mapping
for i in indicators:
es.index('indicators', body=i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment