2016-04-29 45 views
0

如果有2個文件分別有5個詞「world」,分別爲&。按詞頻計數排序結果

所以我要5次有文字「世界」的文件首先列出,然後是有文字「世界」2次的文件。

我該如何分類?

謝謝。

回答

0

我不認爲有任何需要對其進行分類。如果您提供了文檔,並且您正在搜索特定單詞,這個單詞出現在您的案例中多於一,二或三,則彈性搜索會自動計算其分數,並通過分數排序返回文檔。

要嘗試這個攝取一些文檔:

curl -XPUT "http://localhost:9200/movies/movie/1" -d' 
{ 
    "title": "The Godfather", 
    "director": "Francis Ford Coppola", 
    "year": 1972, 
    "genres": [ 
    "Crime", 
    "Drama" 
    ] 
}' 

curl -XPUT "http://localhost:9200/movies/movie/2" -d' 
{ 
    "title": "The Godfather Godfather", 
    "director": "Francis Ford Coppola", 
    "year": 1972, 
    "genres": [ 
    "Crime", 
    "Drama" 
    ] 
}' 

curl -XPUT "http://localhost:9200/movies/movie/3" -d' 
{ 
    "title": "The Godfather Godfather Godfather", 
    "director": "Francis Ford Coppola", 
    "year": 1972, 
    "genres": [ 
    "Crime", 
    "Drama" 
    ] 
}' 

攝入運行此查詢後,看到的結果:

curl -XPOST "http://localhost:9200/movies/_search" -d' 
{ 
    "explain": true, 
    "query": { 
    "filtered": { 
     "query": { 
     "query_string": { 
      "query": "godfather" 
     } 
     } 
    } 
    } 
}' 

這將返回在上面的文檔的三種因爲它有「教父」多時間