Elasticsearch-dsl-py: Exception always raised when saving a document using pypy but not when using cpython

Created on 17 Jul 2018  路  8Comments  路  Source: elastic/elasticsearch-dsl-py

I have some code that saves data to Elasticsearch. It runs fine in Python 3.5.2 (cpython), but raises an exception when running on pypi3 6.0.0 (Python 3.5.3). Any ideas why?

File "/opt/venvs/parsedmarc/site-packages/parsedmarc/elastic.py", line 366, in save_forensic_report_to_elasticsearch
  forensic_doc.save()
File "/opt/venvs/parsedmarc/site-packages/elasticsearch_dsl/document.py", line 394, in save
  index=self._get_index(index),
File "/opt/venvs/parsedmarc/site-packages/elasticsearch_dsl/document.py", line 138, in _get_index
  raise ValidationException('You cannot write to a wildcard index.')
elasticsearch_dsl.exceptions.ValidationException: You cannot write to a wildcard index

Looking at document.py, that exception is only supposed to be raised when a save attempt is made on an index name that contains *.

I set the index name using a Meta class as as you can see here, and there is not any * in the index variable.

Here's some basic sample code to reproduce the issue:

Note: you must have an Elasticsearch instance running to reproduce the issue.

from elasticsearch_dsl import DocType, Text, connections

class _ForensicReportDoc(DocType):
    class Meta:
        index = "sample_index"

    feedback_type = Text()

connections.create_connection(hosts=["127.0.0.1"], timeout=20)

doc = _ForensicReportDoc(feedback_type="foo")
doc.save()

Most helpful comment

Thank you for the report. The code that is responsible for setting the index name has been moved to class Index in 6.2.0 so now you have to do:

class _ForensicReportDoc(Document):
    class Index:
        name = 'sample_index'

Since it works for you in one environment and not another one is it possible that you have different versions?

Hope this helps!

All 8 comments

Thank you for the report. The code that is responsible for setting the index name has been moved to class Index in 6.2.0 so now you have to do:

class _ForensicReportDoc(Document):
    class Index:
        name = 'sample_index'

Since it works for you in one environment and not another one is it possible that you have different versions?

Hope this helps!

I just checked and updated both environments to 6.2.1, and the code to use the Index class. Same result. It's really weird.

Can you check what happens when you access ._index or ._get_inde() on the document object? Thanks!

I am encountering the same problem, and I have tried all combinations of Meta and Index class, DocType and Document... all throw the same error, not being able to find the index. ._index returns an object, but ._get_index() returns nothing.

*Update

This is what solved a problem for me:

    class Index:
        index = 'sample_index'
        name = 'sample_index'

I am still using DocType, and not Document, switching it is probably a good idea.

Note: debugging confirmed that name of the index never got properly populated. I hope there is a more permanent fix for that.

Thank you all for the reports, this is indeed something we need to fix more permanently.

The solution should be:

class Index:
    name = 'my-index-name'

In my case, I was already using the name attribute. The solution for me was to change references of DocTypetoDocument`. So it seems both changes are needed for Pypy to work. I'm not sure why backwards comparable naming isn't working like it is in CPython.

closing this as there is a workaround and it is only in a deprecated functionality

While using elasticsearch-dsl 6.3.1 with elasticsearch 6.3.1. This is error is re-occuring, as the response dictionary doesnot have a key result, there is a key created with value True/False. This bug has been fixed locally, should create a PR

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rokcarl picture rokcarl  路  4Comments

ypkkhatri picture ypkkhatri  路  4Comments

njoannin picture njoannin  路  3Comments

vmogilev picture vmogilev  路  4Comments

primoz-k picture primoz-k  路  4Comments