es-django-example
es-django-example copied to clipboard
parent/child mapping does not seem to work with ElasticSearch 6
# search.py
class Org(DocType):
name = Text(required=True)
state = Keyword()
employee_size_range = Keyword()
revenue_range = Keyword()
lifetime_revenue_range = Keyword()
street_address = Keyword()
city = Keyword()
postal_code = Keyword()
website = Text()
class Contact(DocType):
first_name = Keyword()
last_name = Keyword()
job_title = Text()
email = Keyword()
class Meta:
parent = MetaField(type='org')
# create an index and register the doc types
index = Index(settings.ES_INDEX)
index.settings(number_of_shards=1, number_of_replicas=0)
index.doc_type(Org)
index.doc_type(Contact)
When trying to fill the index with index_data
I get elasticsearch.helpers.BulkIndexError
with "reason": "routing is required for [stack]/[doc]/[some-document-id]"
.
The created mapping looks like
{
"stack": {
"mappings": {
"doc": {
"_parent": {
"type": "org"
},
"_routing": {
"required": true
},
"properties": {
"email": {
"type": "keyword"
},
"first_name": {
"type": "keyword"
},
"job_title": {
"type": "text"
},
"last_name": {
"type": "keyword"
}
}
}
}
}
}
which doesn't look right to me! Looks like the Org mapping has been overridden by the Contact mapping.
I've tried adding doc_type='org'
doc_type='contact'
to the DocType Meta options, but ES 6 does not allow multiple doc types. I assume there is some way to make this work in ES6 but I'm not seeing it. Am I missing something or is this broken for ES6?
You can no longer have multiple doc types in an index. If you are using the latest elasticsearch-dsl you can make a type of InnerDoc
for something you want nested.
I think it is now suggested to only use doc
for the document type name.
@aschriner there is currently a pull request with a example on how to do this with the new Join
field
https://github.com/elastic/elasticsearch-dsl-py/pull/865/files#diff-caba059a7c2e8c265658722732b4a88bR75