{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/285","labels_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/285/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/285/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/285/events","html_url":"https://github.com/elastic/elasticsearch-dsl-py/issues/285","id":115306910,"number":285,"title":"Search not wrapping results into objects","user":{"login":"wanthalf","id":1882909,"avatar_url":"https://avatars.githubusercontent.com/u/1882909?v=3","gravatar_id":"","url":"https://api.github.com/users/wanthalf","html_url":"https://github.com/wanthalf","followers_url":"https://api.github.com/users/wanthalf/followers","following_url":"https://api.github.com/users/wanthalf/following{/other_user}","gists_url":"https://api.github.com/users/wanthalf/gists{/gist_id}","starred_url":"https://api.github.com/users/wanthalf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wanthalf/subscriptions","organizations_url":"https://api.github.com/users/wanthalf/orgs","repos_url":"https://api.github.com/users/wanthalf/repos","events_url":"https://api.github.com/users/wanthalf/events{/privacy}","received_events_url":"https://api.github.com/users/wanthalf/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-11-05T15:23:05Z","updated_at":"2015-11-06T13:46:50Z","closed_at":null,"body":"I cannot get results of search wrapped as the persistent object types. I tried both MyClass.search() and Search().doc_type(MyClass) as well as both iterating over the response and response.hits, but I only get strings or AttrDict objects. What am I doing wrong?"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/comments/154413823","html_url":"https://github.com/elastic/elasticsearch-dsl-py/issues/285#issuecomment-154413823","issue_url":"https://api.github.com/repos/elastic/elasticsearch-dsl-py/issues/285","id":154413823,"user":{"login":"wanthalf","id":1882909,"avatar_url":"https://avatars.githubusercontent.com/u/1882909?v=3","gravatar_id":"","url":"https://api.github.com/users/wanthalf","html_url":"https://github.com/wanthalf","followers_url":"https://api.github.com/users/wanthalf/followers","following_url":"https://api.github.com/users/wanthalf/following{/other_user}","gists_url":"https://api.github.com/users/wanthalf/gists{/gist_id}","starred_url":"https://api.github.com/users/wanthalf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wanthalf/subscriptions","organizations_url":"https://api.github.com/users/wanthalf/orgs","repos_url":"https://api.github.com/users/wanthalf/repos","events_url":"https://api.github.com/users/wanthalf/events{/privacy}","received_events_url":"https://api.github.com/users/wanthalf/received_events","type":"User","site_admin":false},"created_at":"2015-11-06T13:46:49Z","updated_at":"2015-11-06T13:46:49Z","body":"No exception. I get exception from Object.get(), but not from Object.search().execute().\r\n\r\nTak jo:\r\n```\r\nattr_field = Nested(\r\n    properties={\r\n        'name': field.String(index='not_analyzed'),\r\n        'value': field.String(index='not_analyzed')\r\n    }\r\n)\r\n\r\nclass CType(DocType):\r\n    attrs = attr_field\r\n\r\n    def __init__(self, **kwargs):\r\n        if 'attrs' in kwargs:\r\n            attrs = []\r\n            for k, v in kwargs['attrs'].items():\r\n                attrs.append({'name': k, 'value': v})\r\n            kwargs['attrs'] = attrs\r\n        super().__init__(**kwargs)\r\n```\r\n\r\nIn this configuration I get no exception from Search:\r\n\r\n```\r\n>>> s = CType.search()\r\n>>> s = s.filter('nested', path='attrs', filter={\"bool\":{\"must\":[{\"term\":{\"attrs.name\":\"word\"}},{\"term\":{\"attrs.value\":\"-\"}}]}})\r\n>>> r = s.execute()\r\n>>> type(r.hits[0]).__name__\r\nTraceback (most recent call last):\r\n  File \"<stdin>\", line 1, in <module>\r\n  File \"/usr/local/lib/python3.4/dist-packages/elasticsearch_dsl/utils.py\", line 115, in __getitem__\r\n    return _wrap(self._d_[key])\r\nKeyError: 0\r\n>>> for i in r:\r\n...  print(type(i).__name__)\r\n... \r\nstr\r\nstr\r\nstr\r\n```\r\n\r\nWhen removing the quoted block from the init(), the results are as expected:\r\n\r\n```\r\n>>> s = CType.search()\r\n>>> s = s.filter('nested', path='attrs', filter={\"bool\":{\"must\":[{\"term\":{\"attrs.name\":\"word\"}},{\"term\":{\"attrs.value\":\"-\"}}]}})\r\n>>> r = s.execute()\r\n>>> type(r.hits[0]).__name__\r\n'CType'\r\n>>> for i in r:\r\n...  print(type(i).__name__)\r\n... \r\nCType\r\n```\r\n\r\nMoje chyba, samozřejmě, ale trvalo mi, než jsem na to přišel, že si to nemůžu takhle dovolit.\r\nKaždopádně moc díky za tenhle skvělý balíček!"}}