Search code examples
pythonelasticsearchelasticsearch-dslelasticsearch-dsl-py

elasticsearch-DSL lib set default value for Text field on saving Document


how do we check if a Field object from elasticsearch-DSL lib (e.g. Text, Integer, Keyword) contains no value, say None or empty string? On such case, I need to set the field in Document object with some sort of default but dynamic value, before saving the Document into ES. Thanks.


Solution

  • the easiest way to do this is to override save() method and do it there, you can see an example of it here: https://github.com/elastic/elasticsearch-dsl-py/blob/master/examples/parent_child.py#L84-L85