Created
July 8, 2015 07:50
-
-
Save anonymous/0310ac13b54e7f96ace3 to your computer and use it in GitHub Desktop.
dynamic_template example
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
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