Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parent/child mapping does not seem to work with ElasticSearch 6 #19

Open
aschriner opened this issue Jan 18, 2018 · 2 comments
Open

parent/child mapping does not seem to work with ElasticSearch 6 #19

aschriner opened this issue Jan 18, 2018 · 2 comments

Comments

@aschriner
Copy link

aschriner commented Jan 18, 2018

# 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?

@TheCthulhuKid
Copy link

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.

@netoxico
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants