2

I am new to elasticsearch. I am trying to retrieve the selected fields from nested object returned by elasticsearch. Below is the object stored in elasticsearch index:

{
  "_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
      }
    }
  }
}

Now I want only certain fields to be returned from user.user_auth(like password,superuser etc should not be returned). I am using django PyES and below is the code that i tried:

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)

but the result that I get is only email being retrieved (i:e only last field being returned):

{
  "user.user_auth.email": "nikhiltyagi.eng@gmail.com"
}

I want this abstraction for both the nested objects (i:e user_auth,user_profile)

how do I do this?

Saeed Zhiany
  • 2,051
  • 9
  • 30
  • 41
nikhil tyagi
  • 373
  • 1
  • 4
  • 8

1 Answers1

0

What about using latest django-haystack? It covers also ElasticSearch as a backend so you can get well binded ElasticSearch FTS to your project.

nudzo
  • 17,166
  • 2
  • 19
  • 19