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.
Asked
Active
Viewed 915 times
2 Answers
1
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

Honza Král
- 2,982
- 14
- 11
-
Since the field is initialised with Field object, I expected "if my_field is None:" will evaluate to False. Surprisingly, I just tested it out and the evaluation turns True instead. Since code in the link hints me that my understanding was incorrect, I think it's fair to mark this as answer. – shiouming Sep 01 '18 at 09:10