I have a python model that creates the index as
class Telemetry(DocType): id = Keyword() imei = Keyword() location = field.GeoPoint() timestamp = Date()
I would like to query distinct count of imei. What I have done so far is, but this does not give any output.
def get_telemetry_for_license(): docs = Telemetry.search().aggs.metric('imei_count', 'cardinality', field='imei') return imei_count
Any help on the above i appreciate.
I have also tried other way but it loads default 10,000 docs only and my docs size is few millions. If I increase default size my elasticsearch service does not response. Here is the code for other effort.
def get_telemetry_for_license(): docs = Telemetry.search().source(exclude['location_shape']).extra(size=10000) docs = [doc.__dict__['_d_'] for doc in docs] imei = imei_count=0 for doc in docs: if doc.get("imei") is not None: if doc['imei'] not in imei: imei_count += 1 imei.append(doc['imei']) return imei_count
I would be grateful should you help me in any of my effort.