2016-06-16 51 views
0

我與列的文件:聚集在elasticsearch考慮分數

  • 全文稱爲 '內容'
  • 員工(一個或多個)
  • 列...

我做了這個查詢「Michael Seam 假期」,所以elasticsearch返回了一千個結果。

查詢的結果是確定的。首先,我接到邁克爾縫的假期,然後,假期爲其他員工

在結果的結果,也有與術語「休假」爲幾十個員工,像內容:

  • 邁克爾·波特煤層(1次點擊)
  • 邁克爾縫卡爾(3次點擊)
  • 盧卡斯(30次點擊)
  • 瑪麗亞Fuch(27次點擊)
  • 何塞白色(15次點擊)
  • ...

當我把匯聚了員工列,我接到盧卡斯,瑪麗亞和其他邁克爾·波特縫前,邁克爾縫卡爾,有時他們甚至因爲聚集大小的出現。

如何顯示(在聚合中)只有查詢中包含的員工?可能嗎?

P.S .:我正在使用ES 1.7.5

回答

0

我找到了一種方法。

"aggregatePerEmployee" : { 
    "terms" : { 
     "field" : "employee.raw", 
     "order": { 
      "top_hit": "desc" 
     }, 
     "size" : 4 
    }, 
    "aggs": { 
     "top_hit" : { 
      "max": { 
       "script": "_score" 
      } 
     } 
    } 
} 

通過這種方式,聚合訂單考慮每位員工的最高分數。

查看結果

"aggregatePerEmployee": { 
    "doc_count_error_upper_bound": -1, 
    "sum_other_doc_count": 1145, 
    "buckets": [ 
    { 
     "key": "Michael Seam Carl", 
     "doc_count": 3, 
     "top_hit": { 
     "value": 2.097010612487793 
     } 
    }, 
    { 
     "key": "Michael Seam Porter ", 
     "doc_count": 1, 
     "top_hit": { 
     "value": 2.0433993339538574 
     } 
    }, 
    { 
     "key": "Lucas", 
     "doc_count": 30, 
     "top_hit": { 
     "value": 2.0033993339538574 
     } 
    }, 
    { 
     "key": "Jose White ", 
     "doc_count": 15, 
     "top_hit": { 
     "value": 1.5995635986328125 
     } 
    } 
    ] 
} 

PS:啓用此Groovy腳本,需要編輯elasticsearch.yml,並把它這一行:

script.engine.groovy.inline.aggs: on 

後,重新啓動elasticsearch節點