faceted search - elasticsearch - additional field in aggregation results -


i have following aggregation categories

{     "aggs": {         "category": {             "terms": { "field": "category.name" }         }     } }  // results "category": {     "buckets": [         {             "key": "computer & office",             "doc_count": 365         },         {             "key": "home & garden",             "doc_count": 171         },         {             "key": "consumer electronics",             "doc_count": 49         },     ] } 

how can pass additional field, category.id category buckets, query category.id if aggregation clicked user. i'm not clear how query aggregations, if there's direct way or have make new query , pass bucket key query filters.

use sub-aggregation on category.id, bit more work when looking @ results, think it's better changing mapping:

{   "aggs": {     "name": {       "terms": {         "field": "name"       },       "aggs": {         "id": {           "terms": {             "field": "id"           }         }       }     }   } } 

and results following:

   "aggregations": {       "name": {          "doc_count_error_upper_bound": 0,          "sum_other_doc_count": 0,          "buckets": [             {                "key": "consumer electronics",                "doc_count": 2,                "id": {                   "doc_count_error_upper_bound": 0,                   "sum_other_doc_count": 0,                   "buckets": [                      {                         "key": 2,                         "doc_count": 2                      }                   ]                }             },             {                "key": "computer & office",                "doc_count": 1,                "id": {                   "doc_count_error_upper_bound": 0,                   "sum_other_doc_count": 0,                   "buckets": [                      {                         "key": 5,                         "doc_count": 1                      }                   ]                }             },             {                "key": "home & garden",                "doc_count": 1,                "id": {                   "doc_count_error_upper_bound": 0,                   "sum_other_doc_count": 0,                   "buckets": [                      {                         "key": 1,                         "doc_count": 1                      }                   ]                }             },             {                "key": "whatever",                "doc_count": 1,                "id": {                   "doc_count_error_upper_bound": 0,                   "sum_other_doc_count": 0,                   "buckets": [                      {                         "key": 3,                         "doc_count": 1                      }                   ]                }             }          ]       }    } 

you still have category name, you, also, have id second aggregation sub-bucket in root bucket:

               "key": "consumer electronics",                ...                "id": {                   ...                   "buckets": [                      {                         "key": 2,                         "doc_count": 2 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -