2012-07-10 83 views
2

我是elasticsearch的新手。我试图从elasticsearch返回的嵌套对象中检索选定的字段。下面是存储在elasticsearch索引的对象:从elasticsearch返回的嵌套对象中检索指定的字段

{ 
    "_index": "xxx", 
    "_type": "user", 
    "_id": "2", 
    "_version": 1, 
    "exists": true, 
    "_source": { 
    "user": { 
     "user_auth": { 
     "username": "[email protected]", 
     "first_name": "", 
     "last_name": "", 
     "is_active": false, 
     "_state": { 
      "adding": false, 
      "db": "default" 
     }, 
     "id": 2, 
     "is_superuser": false, 
     "is_staff": false, 
     "last_login": "2012-07-10 21:11:53", 
     "password": "sha1$a6caa$cba2f821678ccddc4d70c8bf0c8e0655ab5c279b", 
     "email": "[email protected]", 
     "date_joined": "2012-07-10 21:11:53" 
     }, 
     "user_account": {}, 
     "user_profile": { 
     "username": null, 
     "user_id": 2, 
     "following_count": 0, 
     "sqwag_count": 0, 
     "pwd_reset_key": null, 
     "_state": { 
      "adding": false, 
      "db": "default" 
     }, 
     "personal_message": null, 
     "followed_by_count": 0, 
     "displayname": "nikhil11", 
     "fullname": "nikhil11", 
     "sqwag_image_url": null, 
     "id": 27, 
     "sqwag_cover_image_url": null 
     } 
    } 
    } 
} 

现在我想从user.user_auth返回只有某些领域(如密码,超级用户等不应该退还)。 我使用Django PyES以下是我试过的代码:

fields = ["user.user_auth.username","user.user_auth.first_name","user.user_auth.last_name","user.user_auth.email"] 
result = con.search(query=q,indices="xxx",doc_types="user",fields=fields) 

但我得到的是被检索仅电子邮件的结果(我:返回Ë只有最后一个字段):

{ 
    "user.user_auth.email": "[email protected]" 
} 

我想要这个嵌套对象的抽象(我:user_auth,user_profile)

我该怎么做?

回答

0

如何使用最新的django-haystack?它还包括ElasticSearch作为后端,因此您可以将ElasticSearch FTS绑定到您的项目。

相关问题