facets - Elasticsearch custom Aggregation Result -


in developed training module, there page lists courses table view filterable header. 1 of columns "saved" column "saved" if bookmarked , "unsaved" if not.

the course entity indexed below:

{   "_index": "myindex",   "_type": "course",   "_id": "248fc0a2-06e1-11e6-b740-000c298fdb4d",   "_score": 1,   "_source": {   "boost_number": 1,   "entity_type_number": 64,   "course_status_string": "closed",   "title": "my test course",   "body": "this test course",   "created_date": "20160420t101753z",   "categories_uuid": [ ],   "segment_string": [     "other"   ],   "vertical_string": [     "other"   ],   "saved_users_uuid": [     "251bde26-4adf-11e4-b705-000c298fdb4d",     "00026884-7cc8-11e3-a570-fa163e2bcb7a",     "00061164-9283-11e5-a394-000c298fdb4d",     "00110a72-0b8b-11e4-9a64-fa163e2bcb7a",   ] } 

let's had logged in id: "251bde26-4adf-11e4-b705-000c298fdb4d". when querying elastic facets, received bucket:

"saved_users" : {     "doc_count_error_upper_bound": 0,      "sum_other_doc_count": 0,      "buckets" : [          {             "key" : "251bde26-4adf-11e4-b705-000c298fdb4d",             "doc_count" : 5         },         {             "key" : "00026884-7cc8-11e3-a570-fa163e2bcb7a",             "doc_count" : 0         },         ...     ] } 

however, have custom bucket such as:

{   ...   "buckets": [     {       "key": "saved",       "doc_count": ...     },     {       "key": "unsaved",       "doc_count": ...     },   ] } 

is possible? how that?

you can try add following filters aggregation:

{   "size": 0,   "aggs": {     "category": {       "filters": {         "filters": {           "saved": {             "exists": {               "field": "saved_users_uuid"             }           },           "unsaved": {             "missing": {               "field": "saved_users_uuid"             }           }         }       }     }   } } 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -