0

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.

shiouming
  • 1,889
  • 4
  • 17
  • 26

2 Answers2

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
-1

I don't think it's possible with current implementation. Details are available here. However, if you are using elasticsearch rest client, you can add logic to generate some random String/Number before saving.

Biplab
  • 139
  • 6