Hmm... on further review it looks like my solution might not have gone
far enough. It works for Date/DateTime. However, due to the type
casting that occurs in the various type specific SearchField
implementations, it looks like other field types containing null
values get coerced into non-nulls values and thus included in the
document. A solution could be to add null checks to these type
specific implementations. For example:
class IntegerField(SearchField):
def __init__(self, **kwargs):
kwargs['default'] = 0
super(IntegerField, self).__init__(**kwargs)
def prepare(self, obj):
value = super(IntegerField, self).prepare(obj)
if value != None
return int(value)
else:
return None