Weight
The weight query is also a query that Es has that MySQL does not have, and the syntax is as follows
# API
function(field, value, Float weight value)
1
# Code example
@Test
public void testWeight() throws IOException {
// Test weight
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
String keyword = "overdrive";
float contentBoost = 5.0f;
wrapper.match(Document::getContent,keyword,contentBoost);
String creator = "old man";
float creatorBoost = 2.0f;
wrapper.eq(Document::getCreator,creator,creatorBoost);
SearchResponse response = documentMapper.search(wrapper);
System.out.println(response);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
Warm tips
If you need to score, then return through SearchResponse, if you do not need to score, just need to return according to the high score of the first rank, then directly with List<T>
to receive can.
Help us improve this document (opens new window)
Last update: 2024/03/29