django-es / django-elasticsearch-dsl

This is a package that allows indexing of django models in elasticsearch with elasticsearch-dsl-py.
Other
1.02k stars 264 forks source link

BulkIndexError when indexing an ObjectField #143

Open mrsdz opened 5 years ago

mrsdz commented 5 years ago

Hi I'm trying to save a JSONField in Django admin and I got this error: BulkIndexError

I'm trying to save: {"size": "XL", "color": 2} But everything is okay with: {"size": "1", "color": 2}

My ObjectField Document:

attributes = fields.ObjectField()

def prepare_attributes(self, instance):
    return instance.attributes

My Model:

attributes = JSONField(default=dict, blank=True)

bors-ltd commented 5 years ago

Check your mapping in ES, maybe if you started by indexing "size": "1", as you didn't specify anything, ES thought it was an integer and created the mapping for it. So it would reject "XL" as not being an integer.

Just an hypothesis as I don't have more details.