2013-03-14 50 views
2

我是ES新手,嘗試使用java apis進行搜索。我無法弄清楚如何使用java apis提供特定的提升。 這裏是例子: 我的索引文件是這樣的:ElasticSearch使用java api進行字段提升

_source「:{

"th_id": 1, 
"th_name": "test name", 
"th_description": "test desc", 
"th_image": "test-img", 
"th_slug": "Make-Me-Smart", 
"th_show_title": "Coast Tech Podcast", 
"th_sh_category": "Alternative Health 

}

當我搜索的關鍵詞我想提高的結果更高,如果他們在發現「th_name」相比,他們在其他一些領域發現。 目前我使用下面的代碼進行搜索:

QueryBuilder qb1 = QueryBuilders.multiMatchQuery(keyword, "th_name", "th_description", "th_show_title", "th_sh_category"); 
SearchResponse response = client.prepareSearch("talk").setTypes("themes") 
     .setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setQuery(qb1) 
     .setFrom(start).setSize(maxRows) 
     .setExplain(true).execute().actionGet(); 

如果在「th_name」字段中找到與在其他字段中找到的關鍵字相關的關鍵字,那麼在查詢時我可以做些什麼來增強文檔?

回答

9

你也應該能夠直接拉動的多匹配查詢字段:

「multi_match查詢支持在字段json字段中通過^符號進行字段提升。

{ 
    "multi_match" : { 
    "query" : "this is a test", 
    "fields" : [ "subject^2", "message" ] 
    } 
} 

在上述示例中,主題字段中的匹配比信息字段中的重要2倍。「

在Java的API,只需使用MultiMatchQueryBuilder:

MultiMatchQueryBuilder builder = 
new MultiMatchQueryBuilder(keyword, "th_name^2", "th_description", "th_show_title", "th_sh_category"); 

免責聲明:未經測試

+0

這是完美的。感謝您提供Java版本。 – apatel 2013-03-16 20:39:34

相關問題