Search code examples
pythonelasticsearchelasticsearch-dslelasticsearch-mapping

Not able to create document with elasticsearch dsl if give boolean type with false value


I have code as below

from elasticsearch_dsl.connections import connections
from elasticsearch_dsl import DocType, String, Boolean

class BaseDoc(DocType):
    id = String(required=True, index='not_analyzed')
    name = String(required=True)
    deleted = Boolean(required=True, null_value=True)

    class Meta:
        index = 'test'


class MyDoc(BaseDoc):
    pass

connections.create_connection(hosts=['localhost:9200'])

MyDoc.init()

doc = MyDoc(id='test', name='test', deleted=False)

doc.save(refresh=True)

I get error

Traceback (most recent call last):
  File "/tmp/test.py", line 31, in <module>
    doc.save(refresh=True)
  File "/usr/lib/python2.7/site-packages/elasticsearch_dsl/document.py", line 240, in save
    self.full_clean()
  File "/usr/lib/python2.7/site-packages/elasticsearch_dsl/utils.py", line 453, in full_clean
    self.clean_fields()
  File "/usr/lib/python2.7/site-packages/elasticsearch_dsl/utils.py", line 447, in clean_fields
    raise ValidationException(errors)
elasticsearch_dsl.exceptions.ValidationException: {'deleted': [ValidationException('Value required for this field.',)]}

if you see, I am passing delete=False in code when I try to create the doc object.

When its not taking deleted value?

If i remove deleted

doc = MyDoc(id='test', name='test')

doc.save(refresh=True)

Then also it gives same error, seems deleted is not taken care by elasticsearch dsl.


Solution

  • The issue you're facing issue was fixed in PR #390.

    So it looks like you're still using the release 0.0.11. If you're using ES 2.x, you should upgrade to upgrade to release 2.2.0 and if you're using ES 5.x then you should upgrade to release 5.1.0 and your issue should be fixed.