question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Document mapping doesn't accept any name but 'doc'

See original GitHub issue

I tried to use the new 6.2 release and found that the following code crashes:

from elasticsearch_dsl import Document, Mapping

class MyDoc(Document):
    class Meta:
        mapping = Mapping('a')

With the following trace:

/lib/python3.6/site-packages/elasticsearch_dsl/document.py in __new__(cls, name, bases, attrs)
     30         new_cls = super(IndexMeta, cls).__new__(cls, name, bases, attrs)
     31         new_cls._index = cls.construct_index(index_opts, bases)
---> 32         new_cls._index.document(new_cls)
     33         return new_cls
     34

/lib/python3.6/site-packages/elasticsearch_dsl/index.py in document(self, document)
    121             raise IllegalOperation(
    122                 'Index object cannot have multiple types, %s already set, '
--> 123                 'trying to assign %s.' % (self._mapping.doc_type, name))
    124         self._doc_types.append(document)
    125         # TODO: do this at save time to allow Document to be modified after

IllegalOperation: Index object cannot have multiple types, doc already set, trying to assign a.

I tried to add doc_type='a' to the Meta class, but it didn’t help. As far as I have tried, there’s absolutely no way to have a mapping which is not named 'doc'. This is also incompatible with existing indexes.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
honzakralcommented, Aug 17, 2018

Thank you all for your patience, I just pushed a fix that should make the part in class Index optional, so just defining a class Meta: doc_type = "a" should be enough.

I also cleaned up a lot of faulty logic when it came to Index handling. If you could test the current master (69f5ca2dc7657c26a19f11d75b7c2080afcfcdd6) I would be most grateful! After it has been tested I will release it as 6.3.0

2reactions
jason-hulingcommented, Aug 17, 2018

@rafaelcaricio, turns out I should have troubleshot a little longer 😄 …

The following worked for me to avoid elasticsearch_dsl.exceptions.IllegalOperation:

class MyDoc(Document):
    class Index:
        doc_type = "a"
        
    class Meta:
        doc_type = "a"

I noticed that the following gave the error a already set, trying to assign doc

class MyDoc(Document):
    class Index:
        doc_type = "a"

And this gave the same error but reversed doc already set, trying to assign a

class MyDoc(Document):
    class Meta:
        doc_type = "a"

So setting doc_type in both Index and Meta is required to align them and prevent the error.

@HonzaKral do you know if this behavior is intentional?

Read more comments on GitHub >

github_iconTop Results From Across the Web

You receive error messages when opening an Office document
This issue occurs when you open a file from a mapped drive, a UNC path, ... Microsoft Excel: The total length of the...
Read more >
Name Mapping | TestComplete Documentation
The Name Mapping repository stores all the objects of your tested applications that your automated tests use. For each object, the Name Mapping...
Read more >
Error Messages | Maps JavaScript API - Google Developers
This page describes the error messages that can be returned by the Maps JavaScript API. The Maps JavaScript API writes error and warning...
Read more >
Fine-grained access control in Amazon OpenSearch Service
The access policy accepts or rejects requests at the "edge" of the domain, ... You can't sign a request with a user name...
Read more >
Guidelines for representing your business on Google
We also do not allow solicitation of the above information through local posts or a business description other than the user's own name,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found