2017-01-04 33 views
0

我有一個大的Windows事件日誌集,我試圖從單個事件ID中的單個列中查找用戶的唯一列表。這運行,但需要很長時間。你將如何使用python Elasticsearch_dslElasticsearch-py來實現這個目標?Elasticsearch dsl - Python中單列的大型唯一列表

es = Elasticsearch([localhostmines], timeout=30) 
    s = Search(using=es, index="logindex-*").filter('term', EventID="4624") 

    users = set([]) 
    for hit in s.scan(): 
     users.add(hit.TargetUserName) 

    print(users) 

TargetUserName列包含絃樂器名,EventID列包含事件ID的字符串的窗口。

回答

2

你需要使用一個terms聚合,這將完全符合你的期望。

s = Search(using=es, index="logindex-*").filter('term', EventID="4624") 
s.aggs.bucket('per_user', 'terms', field='TargetUserName') 

response = s.execute() 
for user in response.aggregations.per_user.buckets: 
    print(user.key, user.doc_count) 
+0

感謝您的回答,它看起來好像它會工作,但我最終收到一個search_phase_execution_exception fielddata默認情況下禁用文本字段。並將其設置爲true。你知道另一種解決方法,因爲我沒有能力讓這個設置輕微改變。感謝你的協助。 – johnnyb

+0

你可以分享你的'TargetUserName'字段的映射嗎?這可能是因爲它是一個分析文本字段。你在那個領域有一個關鍵字子字段嗎? – Val

+0

不幸的是,我不能,我不是設備的管理員,我只是試圖使用它的數據進行分析。會有不同的方式來獲取數據嗎? – johnnyb