2017-06-08 18 views
0

字的正確排序評分結果,我們有一個elasticsearch指數具有以下配置:在elasticsearch

PUT phonebook 
{ 
    "settings":{ 
     "index":{ 
     "number_of_shards":8, 
     "number_of_replicas":1 
     } 
    }, 
    "mappings":{ 
     "person":{ 
     "_all":{ 
      "enabled":false 
     }, 
     "_source":{ 
      "enabled":true 
     }, 
     "properties":{ 
      "id":{ 
       "type":"long" 
      }, 
      "name":{ 
       "type":"text", 
       "index_options":"positions" 
      }, 
      "number":{ 
       "type":"long" 
      } 
     } 
     } 
    } 
} 

它基本上與數十億條記錄一個巨大的電話簿。我在尋找這個指數用下面的查詢:

GET /contacts/contact/_search 
{ 
    "size":0, 
    "query":{ 
     "match":{ 
     "name":{ 
      "fuzziness":1, 
      "query":"george bush", 
      "operator":"and" 
     } 
     } 
    }, 
    "aggs":{ 
     "by_number":{ 
     "terms":{ 
      "field":"number", 
      "size":10, 
      "order":{ 
       "max_score":"desc" 
      } 
     }, 
     "aggs":{ 
      "max_score":{ 
       "max":{ 
        "script":"_score" 
       } 
      }, 
      "sample":{ 
       "top_hits":{ 
        "size":1 
       } 
      } 
     } 
     } 
    } 
} 

結果由現場「數量」和最佳匹配分組爲每個號碼這種方式返回。但我需要的是根據結果中單詞順序的正確性對結果進行自定義評分/排序。 因此,對於「喬治布什」的詢問,「喬治布什」總是比「布什喬治」更好。 match_phrase搜索並不適合我,因爲我在搜索時使用了模糊處理。

回答

0

怎麼是這樣的:

"query":{ 
    "simple_query_string": { 
     "query": "\"barack~ obama~\"~3", 
     "fields": ["name"] 
    }  
    }, 

尾隨~以下令牌是模糊的方面和~3短語以下處理這是我認爲你正在尋找的理念短語查詢。我認爲這樣的結果將得分,使得「奧巴馬」比奧巴馬更高。你可以想出一個自定義的bool查詢,它模擬了should子句處理模糊和污點方面的情況。

一些資源: