Skip to content

Instantly share code, notes, and snippets.

@cherryramatisdev
Last active April 28, 2022 21:12
Show Gist options
  • Save cherryramatisdev/ac9651b25c49a54e998aa6ed7d9ee4e8 to your computer and use it in GitHub Desktop.
Save cherryramatisdev/ac9651b25c49a54e998aa6ed7d9ee4e8 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import json
with open("./target.json", "r") as file:
target_file = json.load(file)
for t in target_file["SearchWord"]:
prefix = {"create": {"_index": "searchword", "_type": "_doc"}}
words = {
"word": t["SearchWord"],
"min_age": t["Min_Age_Years"],
"max_age": t["Max_Age_Years"],
"sex": t["Gender"],
"id": t["AlgorithmID"],
}
if not "\r\n" in t["SearchWord"]:
print(json.dumps(prefix) + "\n" + json.dumps(words))
@cherryramatisdev
Copy link
Author

Usage:

  1. Create a target.json file following the pattern:
{
 "SearchWord": [
   {
     "SearchWord": "content"
    }
  ]
}
  1. Run the script
chmod u+x ./json-to-opensearch-format.py
./json-to-opensearch-format.py > output
  1. Copy the output and insert at opensearch dashboard interactive panel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment