Elasticsearch-dsl-py: DocType.mget seems to be missing id fields

Created on 1 Jul 2016  路  3Comments  路  Source: elastic/elasticsearch-dsl-py

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!

Most helpful comment

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

takaomag picture takaomag  路  3Comments

amih90 picture amih90  路  4Comments

barseghyanartur picture barseghyanartur  路  4Comments

Sachin-Kahandal picture Sachin-Kahandal  路  4Comments

mortada picture mortada  路  3Comments