Skip to content

Instantly share code, notes, and snippets.

Created July 8, 2015 07:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/0310ac13b54e7f96ace3 to your computer and use it in GitHub Desktop.
Save anonymous/0310ac13b54e7f96ace3 to your computer and use it in GitHub Desktop.
dynamic_template example
import requests
import json
template = {
"template": "some_index_*",
"settings": {
"index": {
"number_of_replicas": "0",
"number_of_shards": "8",
}
},
"mappings": {
"_default_": {
"_all": {
"enabled": False
},
"properties": {
"H1": {
"properties": {
"sub1": {
"doc_values": True,
"type": "boolean",
"index": "not_analyzed"
},
"sub2": {
"index": "no",
"type": "string"
},
}
}
},
"dynamic_templates": {
"text_indexed_template": {
"match_mapping_type": "string",
"mapping": {
"index": "not_analyzed",
"type": "string",
"doc_values": True
},
"match": "*_idx"
}
},
"_source": {
"compress": False
}
}
},
}
res = requests.put(
url="http://127.0.0.1:9200/" + "_template/my_template/",
data=json.dumps(template)
)
print res.status_code, res.content
new_doc = {
"H1": {
"sub1": True,
"sub2": "testing, testing"
}
}
res = requests.post(
url="http://127.0.0.1:9200/" + 'some_index_tryme/record/',
data=json.dumps(new_doc)
)
print res.status_code, res.content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment