簡體   English   中英

如何在ElasticSearch中突出顯示關鍵字的頻率?

[英]How to highlight frequency of keywords in ElasticSearch?

假設我要搜索三個短語“ Microsoft”,“ Facebook”,“ Google”。

如何使ES返回返回結果中每個術語的頻率?

謝謝!

您可能正在尋找術語匯總:

https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html

本質上,它將按發現的條件對結果進行分類

我認為explain API可能會對您有所幫助。 例如,如果運行以下查詢:

GET /your_index/your_type/_search
{   
    "explain": true, 
    "query" : {
        "match": {
           "company" : "Google"
        }
    }
}

結果可能是:

{
   "took": 9,
   "timed_out": false,
   "_shards": {
      "total": 2,
      "successful": 2,
      "failed": 0
   },
   "hits": {
       "total": 1,
       "max_score": 11.7377,
       "hits": [
       {
            "_shard": 1,
            "_node": "n0eQxWrIIPYPlmcXA",
            "_index": "your_index",
            "_type": "your_type",
            "_id": "76991",
            "_score": 11.7377,
            "_source": {
            "company": "Google",
               "price": "2008"
            },
            "_explanation": {
                "value": 11.7377,
                "description": "weight(id:76991 in 6552) [PerFieldSimilarity], result of:",
             "details": [
              {
                 "value": 11.7377,
                 "description": "fieldWeight in 6552, product of:",
                 "details": [
                    {
                       "value": 1,
                       "description": "tf(freq=1.0), with freq of:",
                       "details": [
                          {
                             "value": 1,
                             "description": "termFreq=1.0"
                          }
                       ]
                    },
                    {
                       "value": 11.7377,
                       "description": "idf(docFreq=2, maxDocs=138180)"
                    },
                    {
                       "value": 1,
                       "description": "fieldNorm(doc=6552)"
                    }
                 ]
              }
           ]
        }
     }
   ]
 }
}

_explanation部分下,您可能會看到文檔頻率:

tf-該術語在特定的打分文檔中重復多少次

idf-該術語在所有文檔中重復多少次(我想您正在尋找什么)

希望能幫助到你!

暫無
暫無

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

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