2017-02-14 4 views
3

私はelasticsearchに次のIDを持つ文書を持っています:AVosj8FEIaetdb3CXpP-私はそれをtf-idfのフィールドのすべての単語にアクセスしようとしています:私が持っているElasticsearch:指定された文書のすべての用語のtf-idfを取得する

GET /cnn/cnn_article/AVosj8FEIaetdb3CXpP-/_termvectors 
{ 
    "fields" : ["author_wording"], 
    "term_statistics" : true, 
    "field_statistics" : true 
}' 

応答は次のとおりです。

{ 
    "_index": "dailystormer", 
    "_type": "dailystormer_article", 
    "_id": "AVosj8FEIaetdb3CXpP-", 
    "_version": 3, 
    "found": true, 
    "took": 1, 
    "term_vectors": { 
    "author_wording": { 
     "field_statistics": { 
     "sum_doc_freq": 3408583, 
     "doc_count": 16111, 
     "sum_ttf": 7851321 
     }, 
     "terms": { 
     "318": { 
      "doc_freq": 4, 
      "ttf": 4, 
      "term_freq": 1, 
      "tokens": [ 
      { 
       "position": 121, 
       "start_offset": 688, 
       "end_offset": 691 
      } 
      ] 
     }, 
     "742": { 
      "doc_freq": 1, 
      "ttf": 1, 
      "term_freq": 1, 
      "tokens": [ 
      { 
       "position": 122, 
       "start_offset": 692, 
       "end_offset": 695 
      } 
      ] 
     }, 
     "9971": { 
      "doc_freq": 1, 
      "ttf": 1, 
      "term_freq": 1, 
      "tokens": [ 
      { 
       "position": 123, 
       "start_offset": 696, 
       "end_offset": 700 
      } 
      ] 
     }, 
     "a": { 
      "doc_freq": 14921, 
      "ttf": 163268, 
      "term_freq": 11, 
      "tokens": [ 
      { 
       "position": 1, 
       "start_offset": 13, 
       "end_offset": 14 
      }, 
      ... 
      "you’re": { 
      "doc_freq": 1112, 
      "ttf": 1647, 
      "term_freq": 1, 
      "tokens": [ 
      { 
       "position": 80, 
       "start_offset": 471, 
       "end_offset": 477 
      } 
      ] 
     } 
     } 
    } 
    } 
} 

それは私の用語頻度(TF)ではなく、TF-IDFのようないくつかの興味深いのフィールドを返します。私はそれを自分で再計算すべきですか?それは良いアイデアですか?どうすればいいですか?

+0

このクエリで回答を表示できますか? – Mysterion

+0

@Mysterion私は自分の答えを更新しました – mel

答えて

3

はい、それはあなたにこのフィールドの用語頻度とttfを持っています - 合計の頻度です(例えばすべてのフィールドの全tfの合計)とdf - ドキュメント頻度応答にそれを持っていた)。あなたはあなたのフィールドだけ、またはすべてのフィールドで計算したいtf-idfを決定する必要があります。あなたの応答から

tf-idf = tf * idf 

idf = log (N/df) 

N = doc_count:あなたは次のことを行う必要があり、TF-IDFを計算します。 Elasticsearchはtf-idfを計算するための実装を提供していないので、自分でそれを行う必要があります。

関連する問題