2016-05-04 34 views
0

我有一大堆我正在編制索引的新聞文章。我想要避免編制大量幾乎相同的文章(例如,新聞服務的文章可能會出現多次,日期格式略有不同)。爲什麼我所有的ElasticSearch更像這個命中得分爲零?

所以我想我會做每個文章更像這個查詢。如果我的得分大於某個截止點的話,那麼我認爲這篇文章已經被編入索引了,而且我不打擾它。

但是,當我運行我更喜歡這個查詢時,我得到的所有匹配回來的分數爲零。我無法分辨是否有預期,如果我做錯了什麼,或者我發現了一個錯誤。

我的查詢是這樣的:

POST _search 
{"query": 
    {"bool": 
    {"filter": [ 
     {"more_like_this": 
     {"fields": ["text"], 
     "like": "Doctor Sentenced In $3.1M Health Care Fraud Scheme Justice Department Documents & Publications \nGreenbelt, Maryland - U.S. District Judge Deborah K. Chasanow sentenced physician [snip]" 
     } 
     } 
    ] 
    } 
} 

而且我回來的結果是:

{ 
    "took": 8, 
    "timed_out": false, 
    "_shards": { 
    "total": 5, 
    "successful": 5, 
    "failed": 0 
    }, 
    "hits": { 
    "total": 390, 
    "max_score": 0, 
    "hits": [ 
     [snip] 

回答

0

我今天正面臨着​​類似的問題,more_like_this查詢沒有返回結果給我。因爲我使用的是非默認路由而不是傳遞_routing

我的查詢看起來像下面,我不得不搜索articledefault_11索引文件字段keywordscontents

GET localhost:9200/alias_default/articles/_search 
{ 
       "more_like_this": { 
        "fields": [ 
         "keywords", 
         "contents" 
        ], 
        "like": { 
         "_index": "default_11", 
         "_type": "articles", 
         "_routing": "6", 
         "_id": "1000000000006000000000000000014" 
        }, 
        "min_word_length": 2, 
        "min_term_freq": 2 
       } 
    } 

還要記住傳遞_routing參數。

This issue typically occurs when documents are indexed with non-default routing

參見:ElasticSearch returns document in search but not in GET

0

的原因是因爲你有一個篩選查詢中的MLT查詢。過濾器查詢總是返回零分。把你的MLT放在一個必須或應該查詢的範圍內,你會得到分數。

0

您得到零分,因爲Bool運算符的Filter部分未包含在計算得分中。它僅用於過濾結果。您應該使用MUST操作員來獲得分數。

POST _search 
{"query": 
    {"bool": 
    {"must": [ 
     {"more_like_this": 
     {"fields": ["text"], 
     "like": "Doctor Sentenced In $3.1M Health Care Fraud Scheme Justice Department Documents & Publications \nGreenbelt, Maryland - U.S. District Judge Deborah K. Chasanow sentenced physician [snip]" 
     } 
     } 
    ] 
    } 
} 

欲瞭解更多信息,請參閱文檔 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html