This documentation is quite confusing. I assumed I could create a dynamic template as outlined here: https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html via the Index.create() method but for the life of me I'm not sure how I'm supposed to pass in the body correctly.
Here is some sample code:
dynamic_template = {
"mappings": {
"page": {
"dynamic_templates": [
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"raw": "keyword",
"ignore_above": 256
}
}
}
}
]
}
}
}
index = Index(name='my_index_name', using=myhost)
index.create(body=dyanmic_template) # this is obviously wrong...
The last line is obviously wrong. I'm not sure what I'm supposed to pass in to the create call. Could I not pass doc_type= 'page' and body=dynamic_template? I get an error saying the Index.create() retrieves multiple body kwargs (since create passes itself as a dict as the body...). What's the proper way to set my mapping??
Currently there is no direct support for dynamic_templates and you have to use the raw dicts to specify those:
class MyDocType(DocType):
class Meta:
dynamic_templates = MetaField([
{
"strings": {
"match_mapping_type": "string",
"mapping": {
"type": "text",
"term_vector": "with_positions_offsets",
"fields": {
"raw": "keyword",
"ignore_above": 256
}
}
}
])
Hope this helps!
Most helpful comment
Currently there is no direct support for
dynamic_templatesand you have to use the raw dicts to specify those:Hope this helps!