我在ElasticSearch中使用Java API搜索某些关键字,并为我的搜索关键字得到了很多结果。但是,我的确切搜索关键字并不位于结果的顶部。
例如:Keyword : AB-7000-8003
我的搜索关键字得到以下答复。
[
{
"code": "AB-7000-8003-W",
"id": "11569",
},
{
"code": "AB-7000-8003",
"id": "11573",
},
{
"code": "AB-7000-8003-WK",
"id": "11565",
},
{
"code": "AB-7000-8003S",
"id": "11557",
},
{
"code": "AB-7000-8003-k",
"id": "11569",
}
]
Am预期结果按如下升序排列,而我的确切搜索关键字应位于结果顶部:
[
{
"code": "AB-7000-8003",
"id": "11573",
},
{
"code": "AB-7000-8003-k",
"id": "11569",
},
{
"code": "AB-7000-8003S",
"id": "11557",
},
{
"code": "AB-7000-8003-W",
"id": "11569",
},
{
"code": "AB-7000-8003-WK",
"id": "11565",
}
]
请在下面找到我的代码:
SearchRequest searchRequest = new SearchRequest(PRODUCTS_INDEX);
searchRequest.types(TYPE);
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
QueryBuilder qb = QueryBuilders.boolQuery().must(QueryBuilders.matchPhraseQuery("product_code", code));
searchSourceBuilder.query(qb);
searchSourceBuilder.size(8000);
searchRequest.source(searchSourceBuilder);
SearchResponse searchResponse = null;
try {
searchResponse = SearchEngineClient.getInstance().search(searchRequest);
} catch (IOException e) {
logger.log(Level.SEVERE, e.getMessage(), e);
ExceptionUtils.handle(e);
}
我使用的是ElasticSearch 6.2.3版本。
答案 0 :(得分:0)
查询按scroe排序
scroe = tf * idf * norm
在关闭后,使用“ norm”:{“ enabled”:false},得分,无论文档字段的长度如何,得分都是相同的。检查索引映射