Easy-Es Easy-Es
💋Home
  • v2.0.0(current version)
  • What's New

    • What' s New In Easy-Es v2.0.0?
  • history version

    • v1.x.x
  • Upgrade guide

    • Upgrade to 2.x.x instructions
💖Support
  • OS Community
  • Recommend Goods
  • Project PPT (opens new window)
  • Project introduction
  • Project members
  • PR
Join
Customer
  • Doc-Apis (opens new window)
  • Fitness plan automatic generation system (opens new window)
  • Vuepress-theme-vdoing (opens new window)
  • Gitee (opens new window)
  • Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)

adv display by random ❤️become sponsor
💋Home
  • v2.0.0(current version)
  • What's New

    • What' s New In Easy-Es v2.0.0?
  • history version

    • v1.x.x
  • Upgrade guide

    • Upgrade to 2.x.x instructions
💖Support
  • OS Community
  • Recommend Goods
  • Project PPT (opens new window)
  • Project introduction
  • Project members
  • PR
Join
Customer
  • Doc-Apis (opens new window)
  • Fitness plan automatic generation system (opens new window)
  • Vuepress-theme-vdoing (opens new window)
  • Gitee (opens new window)
  • Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)
  • Quick start

    • Introduction
    • Applicable scene
    • Worry free
    • Avoid pit
    • Quick start
    • Springboot demo
    • Config
    • Annotation
  • Core functions

    • Auto process index
    • CRUD
    • Condition constructor
  • Extended function

    • Mixed query
    • Origin query
    • Page
    • Nested
    • Join Parent child
    • Get DSL
  • High-level syntax

    • Field filtering
    • Sort
    • Aggregation
    • Match
      • Token matching related function API
      • code example
    • Weight
    • Highlight
    • Geo
  • Plugin

    • Plugin
  • Other

    • Faq
    • Difference from MP
    • MySQL and EE syntax comparison
    • Update log
    • Update plan
    • Copyright
    • Thanks
  • v1.xDoc
  • High-level syntax
LaoHan
2023-03-18
目录

Match

# Token matching related function API

match(boolean condition, R column, Object val);
notMatch(boolean condition, R column, Object val, Float boost);

// The following APIs are only supported in version 0.9.12+, if necessary, you can upgrade the EE version by yourself
matchPhase(boolean condition, R column, Object val, Float boost);
matchAllQuery();
matchPhrasePrefixQuery(boolean condition, R column, Object val, int maxExpansions, Float boost);
multiMatchQuery(boolean condition, Object val, Operator operator, int minimumShouldMatch, Float boost, R... columns);
queryStringQuery(boolean condition, String queryString, Float boost);
prefixQuery(boolean condition, R column, String prefix, Float boost);
1
2
3
4
5
6
7
8
9
10

Note

Note: The field index type that needs to be matched by word segmentation must be text, and a tokenizer must be specified for it. The required tokenizer must be installed in advance, otherwise the default tokenizer of es will be used, which is not well supported for Chinese.

  • Participle matching
  • Example: match("content", "Lao Wang")--->content contains the keyword 'Lao Wang' If the granularity of the word segmentation is set relatively fine, Lao Wang may be split into "Lao" and "Wang", As long as the content contains "old" or "king", it can be searched out. For other APIs, please refer to the following code examples.

# code example


    @Test
    public void testMatch(){
        // The input will be segmented, as long as one word in all segmented words matches the content, the data will be queried, ignoring the sequence of word segmentation
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.match(Document::getContent,"Technology");
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents.size());
    }

    @Test
    public void testMatchPhase() {
        // The input will be segmented, but all the segmented words need to be included in the result, and the order is the same, otherwise the result cannot be queried
        // For example, the data in es is technically strong, if the search keyword is technically strong, the result cannot be queried
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.matchPhase(Document::getContent, "Technology");
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents);
    }

    @Test
    public void testMatchAllQuery() {
        // Query all data, similar to mysql select all.
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.matchAllQuery();
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents);
    }

    @Test
    public void testMatchPhrasePrefixQuery() {
        // Prefix matching query Only the last word of the query string can be used as a prefix
        // The prefix may match thousands of words, which not only consumes a lot of system resources, but also the result is not very useful, so you can provide the input parameter maxExpansions, if not written, the default is 50
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.matchPhrasePrefixQuery(Document::getCustomField, "Ulabala", 10);
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents);
    }

    @Test
    public void testMultiMatchQuery() {
        // Query data containing Pharaoh from multiple specified fields
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.multiMatchQuery("Pharaoh", Document::getTitle, Document::getContent, Document::getCreator, Document::getCustomField);

        // Among them, the default operator is OR, and the default minShouldMatch is 60%. These two parameters can be adjusted as needed, and our api is supported. For example:
        // where AND means that all searched Tokens must be matched, OR means that only one Token matches. minShouldMatch 80 means only query data with a matching degree greater than 80%
        // wrapper.multiMatchQuery("Pharaoh",Operator.AND,80,Document::getCustomField,Document::getContent);

        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents.size());
        System.out.println(documents);
    }

    @Test
    public void queryStringQuery() {
        // Query data containing the keyword old man from all fields
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.queryStringQuery("Old man");
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents);
    }

    @Test
    public void prefixQuery() {
        // Query all data whose creator starts with "next door", such as the old man next door and the old man next door, can be found
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.prefixQuery(Document::getCreator, "Next door");
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents);
    }

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Help us improve this document (opens new window)
Last update: 2024/03/29
Aggregation
Weight

← Aggregation Weight→

Theme by Vdoing | Copyright © 2021-2025 LaoHan | Zhejiang ICP No. 2022020479 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式