i using elasticsearch store click traffic , each row includes topics of page has been visited. typical row looks like:
{   "date": "2017-09-10t12:26:53.998z",   "pageid": "10263779",   "loc_ll": [     -73.6487,     45.4671   ],   "ua_type": "computer",   "topics": [     "trains",     "planes",     "electric cars"   ] } i want each topics keyword if search cars nothing returned. electric cars return result.
i want run distinct query on topics in rows have list of topics used.
doing on pageid like following, unsure how approach topics array.
{   "aggs": {     "ids": {       "terms": {         "field": pageid,         "size": 10       }     }   } } 
your approach querying , getting available terms looks fine. should check mapping. if results cars looks mapping topics analyzed string (e.g. type text instead of keyword). please check mapping field.
put keywordarray {   "mappings": {     "item": {       "properties": {         "id": {           "type": "integer"         },         "topics": {           "type": "keyword"         }       }     }   } } with sample data
post keywordarray/item {   "id": 123,   "topics": [     "first topic", "second topic", "another"   ] } and aggregation:
get keywordarray/item/_search {   "size": 0,   "aggs": {     "topics": {       "terms": {         "field": "topics"       }     }   } } will result in this:
"aggregations": {   "topics": {     "doc_count_error_upper_bound": 0,     "sum_other_doc_count": 0,     "buckets": [       {         "key": "another",         "doc_count": 1       },       {         "key": "first topic",         "doc_count": 1       },       {         "key": "second topic",         "doc_count": 1       }     ]   } } 
Comments
Post a Comment