所以我要,我需要對一些句子對於一些特定的詞的查詢使用案例匹配的每一個字,我的數據集看起來像這樣Elasticsearch:如何獲得分數的匹配查詢
{
"_index": "12_index",
"_type": "skill_strings",
"_id": "AVKv-kM4axmY3fECZw9T",
"_source": {
"str": "SQL Server"
}
},
{
"_index": "12_index",
"_type": "skill_strings",
"_id": "AVKv-kNfaxmY3fECZw9U",
"_source": {
"str": "SQL .net java"
}
},
{
"_index": "12_index",
"_type": "skill_strings",
"_id": "AVKv-kPDaxmY3fECZw9X",
"_source": {
"str": "My SQL java php .net"
}
},
{
"_index": "12_index",
"_type": "skill_strings",
"_id": "AVKv-kOtaxmY3fECZw9W",
"_source": {
"str": "My SQL Server"
}
},
{
"_index": "12_index",
"_type": "skill_strings",
"_id": "AVKv-kOeaxmY3fECZw9V",
"_source": {
"str": "php asp.net Server"
}
}
而我當前的查詢看起來像這樣
GET 12_index/skill_strings/_search
{
"explain": true,
"query" : {
"bool": {
"should": [
{"match_phrase" : { "str" : "SQL Server" }},
{"match_phrase" : { "str" : ".net" }}
]
}
}
}
所以用例是找到任何的詢問技巧的文件,我需要得到每個比賽的個人得分(我需要他們對我稍後計算)。我無法使用匹配文檔的總體分數,而是需要每個匹配的單詞/短語的分數。
使用說明:真正的,爲我提供了得分的解釋,但即時通訊無法找到任何方式把這個比分並在Java中使用
我的Java代碼如下所示
SearchResponse searchResponse = client.prepareSearch(index)
.setQuery(jsonQuery)
.setTypes(type)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setFrom(from).setSize(size).setExplain(true)
.execute()
.actionGet()
for(SearchHit hit : searchResponse.getHits()){
def id = hit.getId()
Map resMap = hit.getSource()
resMap.eplaination = hit.getExplanation().getDetails()
resData.add(resMap)
}
return resData
我可以看到我什麼時候做hit.getExplanation()。getDetails()我得到類org.apache.lucene.search.Explanation的對象,但我不知道如何檢索它的個人分數。歡迎任何幫助。謝謝
雅我明白,但我需要找到分數和相應的查詢片段,因爲我將在整個查詢中有很多其他匹配/範圍查詢,我不需要那些分數。我只需要這個特定查詢的分數。我可以那樣做嗎? –