簡體   English   中英

考慮分數的Elasticsearch匯總

[英]Aggregation on elasticsearch considering the score

我有一個帶有列的文檔:

  • 全文欄稱為“內容”
  • 員工(一個或多個)
  • ...

我將此查詢設為“ Michael Seam Vacation ”,因此elasticsearch返回了數千個結果。

查詢結果正常。 首先,我收到了Michael Seam的假期,然后是其他員工的假期結果

結果中,有數十名員工使用“休假”一詞表示內容,例如:

  • 邁克爾·塞姆·波特(1點擊)
  • 邁克爾·塞姆·卡爾(3點擊)
  • 盧卡斯(30點擊)
  • 瑪麗亞·福奇(27)
  • 何塞·懷特(15點擊)
  • ...

當我為員工欄添加匯總時,我在Michael Seam Porter和Michael Seam Carl之前收到了Lucas,Maria和其他人,有時由於匯總的大小,它們甚至出現了。

如何僅顯示(匯總)查詢中包含的員工? 可能嗎?

PS:我正在使用ES 1.7.5

我找到了一種方法。

"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:要啟用此常規腳本,有必要編輯elasticsearch.yml並在其上添加以下行:

script.engine.groovy.inline.aggs: on

之后,重新啟動您的elasticsearch節點

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM