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.md
    • Applicable scene
    • Worry free
    • Avoid pit
    • Quick start
    • Springboot demo
    • Spring Integration Guide
    • Solon Integration Guide
    • Config
    • Annotation
  • Core function

    • Condition constructor

      • Introduction of Wrapper
      • Index wrapper
      • Select wrapper
      • Update wrapper
    • Index CRUD

      • Index hosting model
      • Index CRUD
    • Data CRUD

      • Data synchronization solutions
      • Data CRUD
    • Multiple data sources support
    • Dynamic indexing support
    • Four nested query
    • Chain call
  • Extended function

    • Mixed query
    • Origin query
    • Page
    • Nested
    • Join parent child
    • Get DSL
    • ExecuteDSL
    • Execute SQL
    • Custom RequestOptions
    • Custom default method
  • High-level syntax

    • Field filtering
    • Sort
    • Aggregation
    • Match&fuzzy match
      • Word Segmentation Matching Related Function API
      • Fuzzy matching related function API
      • Query API and field index type reference
      • Code examples
    • Weight
    • Highlight
    • Geo
    • IP
  • Plugin

    • Plugin
  • Other

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

Match&fuzzy match

# Word Segmentation Matching Related Function API

match(boolean condition, R column, Object val);
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

attention

Note: The index type of the field that needs word segmentation matching must be text or keyword_text (this type is the default if it is not specified), and a word divider must be specified for it. The required word divider must be installed in advance, otherwise the es default word divider will be used, which is not good for Chinese support.

# Fuzzy matching related function API

//Pay attention to the wildcard query of es at the bottom of like, and the passed-in value will be spliced with the * wildcard by default, such as * old man *
like(boolean condition, String column, Object val, Float boost);
// likeLeft will splice the wildcard * such as * old man on the left side of the value.
likeLeft(boolean condition, String column, Object val, Float boost);
// likeRight will splice wildcard characters * such as Old Man * on the right side of the value.
likeRight(boolean condition, String column, Object val, Float boost);
1
2
3
4
5
6

# Query API and field index type reference

Students who don't know ES can refer to the following table for how to choose the above API and how to correctly establish the corresponding index:

ES native Easy-Es keyword type text type Does word segmentation support
$ text EQ Exact match Query criteria must all be in the word segmentation, and they cannot be redundant. Multiple word segmentation must be continuous', and the order cannot be reversed No
wildcard like/likeLeft/likeRight Fuzzy matching like full fuzzy, like left fuzzy and like right fuzzy according to api Not supported No
match match Exact match As long as the word segmentation result of Match and the word segmentation result of text are the same, ` regardless of the order' Yes
matchPhrase matchPhrase Exact match The word segmentation results of Matchphrase must be all contained' in the word segmentation of the text field and all in the same order, and must be all continuous `. Yes
matchPhrasePrefixquery MatchPhrasePrefixquery Not supported MatchPhrasePrefix is the same as matchPhrase, except that it allows prefix matching on the last word of the text. is
MultimatchQuery MultimatchQuery Complete Match Full-field Word Segmentation Matching, which can realize full-text retrieval function Yes
queryString query querystring query Exact match At least one word segmentation result in querystring is in the word segmentation result in the text field, regardless of the order Yes
prefixQuery prefixQuery Exact Match As long as there are entries in the segmented entries that meet the prefix conditions Yes

-Word segmentation matching -example: match("content ","Lao Wang ")-> The content contains the keyword" Lao Wang ".If the granularity of word segmentation is set fine, Lao Wang may be divided into" Lao "and" Wang ",so long as the content contains" Lao "or" Wang ",they can all be searched out. For other APIs, please refer to the following code examples.

# Code examples


    @Test
    public void testMatch(){
        // The input will be divided into words, as long as there is a match in the content of all the words in the division, the data will be queried, regardless of the order of the words
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.match(Document::getContent, "technology");
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents.size());
    }    

    @Test
    public void testMatchPhrase() {
        // will do the input word, but the results also need to contain all the word, and the same order, otherwise it will not be able to query the results
        // For example, if the data in es is technically sound, if the search term is technically sound, the result will not be queried
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.matchPhrase(Document::getContent, "technical");
        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 match query The last word of the query string can only be used as a prefix
        // Prefixes may match thousands of words, which not only consumes a lot of system resources, but also the results are not very useful, so you can provide the reference maxExpansions, if not written, the default is 50
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.matchPhrasePrefixQuery(Document::getCustomField, "Ullabala", 10);
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents);
    }

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

        // where the default Operator is OR and the default minShouldMatch is 60% Both parameters can be adjusted on demand, which is supported by our api For example:
        // where AND means that all search tokens must be matched, OR means that only one token can be matched. minShouldMatch 80 means only query data with a match greater than 80%.
        // wrapper.multiMatchQuery("Old King",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 the 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 king next door, the man next door, all can be found
        LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
        wrapper.prefixQuery(Document::getCreator, "next door");
        List<Document> documents = documentMapper.selectList(wrapper);
        System.out.println(documents);
    }

    @Test
    public void like() {
            // equivalent to MySQL like %han push% like old man push... can then be checked out
            LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
            wrapper.like(Document::getTitle, "HanTui");
            List<Document> documents = documentMapper.selectList(wrapper);
            System.out.println(documents);
    }

    @Test
    public void likeLeft() {
            // Equivalent to like %han in MySQL Like old man can be checked out
            LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
            wrapper.likeLeft(Document::getTitle, "Han");
            List<Document> documents = documentMapper.selectList(wrapper);
            System.out.println(documents);
    }

    @Test
    public void likeRight() {
            // Equivalent to like old % in MySQL like old man can be checked out
            LambdaEsQueryWrapper<Document> wrapper = new LambdaEsQueryWrapper<>();
            wrapper.likeRight(Document::getTitle, "old");
            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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式