Field filtering
if you don't want to look up some big fields in some queries, you can filter the fields of the query.
# 1. Forward filtering (only query the specified field)
@Test
public void testFilterField() {
//The test only queries the specified fields.
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
String title = "old man";
wrapper.eq(Document::getTitle, title);
wrapper.select(Document::getTitle);
Document document = documentMapper.selectOne(wrapper);
System.out.println(document);
}
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 2. Reverse filtering (do not query the specified field)
@Test
public void testNotFilterField() {
//The test does not query the specified field (recommended)
LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
String title = "old man";
wrapper.eq(Document::getTitle, title);
wrapper.notSelect(Document::getTitle);
Document document = documentMapper.selectOne(wrapper);
System.out.println(document);
//another Lambda writing method consistent with mp grammar
LambdaEsQueryWrapper<Document> wrapper1 = new LambdaEsQueryWrapper<>();
wrapper1.select(Document.class, d -> ! Objects.equals(d.getColumn(), "title"));
Document document1 = documentMapper.selectOne(wrapper);
System.out.println(document1);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
提示
You can only choose one of forward filtering and reverse filtering. If you use both filtering rules at the same time, the conflicting fields will lose their filtering effect.
Help us improve this document (opens new window)
Last update: 2024/03/29