Hey there, how are you? Hope you are fine! :-)
I've just updated to 2.1.0 and tried to use mget from DocType. It doesn't return the object ids.
It seems that it happens because documents get converted on DishType.from_es (https://github.com/elastic/elasticsearch-dsl-py/blob/69d8f19c5c0ba252785de008c11c0454df229314/elasticsearch_dsl/document.py#L176)
I understand this could be easily dealt with by overriding from_es classmethod, but I feel like that, by default, it would be a nice idea to include at least the id. Maybe even _parent and _routing (mixed feelings about these, though).
What do you guys think?
Thanks!
Hi, I am afraid I don't know what you mean. Ids are retrieved correctly for me:
>>> from elasticsearch_dsl import DocType, String
>>> class T(DocType):
... title = String()
... class Meta:
... index = 'i'
>>> t = T(title='first', _id=42)
>>> t.save()
True
>>> t2 = T.mget([42])[0]
>>> t2.meta.id
'42'
Yep, Indeed. Sorry for that @HonzaKral.
I tried to get the result and figure out they keys it had (using dir, to_dict.keys(), etc). It didn't show up either way.
Sorry for the issue! I'm closing it.
Yes, to_dict by default only serializes the data, not the metadata. If you want to see those as well, do to_dict(include_meta=True).
Hope that helps.
Most helpful comment
Yes,
to_dictby default only serializes the data, not the metadata. If you want to see those as well, doto_dict(include_meta=True).Hope that helps.