我是弹性搜索的新手。我正在尝试从 elasticsearch 返回的嵌套对象中检索选定的字段。下面是存储在 elasticsearch 索引中的对象:
{
"_index": "xxx",
"_type": "user",
"_id": "2",
"_version": 1,
"exists": true,
"_source": {
"user": {
"user_auth": {
"username": "nickcoolster@gmail.com",
"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": "nickcoolster@gmail.com",
"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": "nikhiltyagi.eng@gmail.com"
}
我想要嵌套对象的这种抽象(即:user_auth,user_profile)
我该怎么做呢?