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

    • What' s New In Easy-Es v2.1.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)
  • GitCode (opens new window)
  • Github (opens new window)
  • 简体中文 (opens new window)
  • English (opens new window)

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

    • What' s New In Easy-Es v2.1.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)
  • GitCode (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
        • LambdaEsIndexWrapper
          • API description
          • Use cases
      • 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
    • Weight
    • Highlight
    • Geo
    • IP
  • Plugin

    • Plugin
  • Other

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

Index wrapper

# LambdaEsIndexWrapper

提示

The relevant conditions in the CRUD of the index depend on this constructor for wrapping

# API description

LambdaEsIndexWrapper provides the following APIs for use by users

    mapping(R column, FieldType fieldType);
    mapping(R column, FieldType fieldType, Boolean fieldData);
    mapping(R column, FieldType fieldType, Float boost);
    mapping(R column, FieldType fieldType, Boolean fieldData, Float boost);
    mapping(R column, FieldType fieldType, String dateFormat);
    mapping(R column, FieldType fieldType, String analyzer, String searchAnalyzer);
    mapping(R column, FieldType fieldType, String analyzer, String searchAnalyzer, String dateFormat);
    mapping(R column, FieldType fieldType, String analyzer, String searchAnalyzer, Float boost);
    mapping(R column, FieldType fieldType, String analyzer, String searchAnalyzer, String dateFormat, Boolean fieldData, Float boost);
    mapping(Map<String, Object> mapping);
    
    createAlias(String aliasName);
    settings(Settings settings);
    settings(Integer shards, Integer replicas);
    maxResultWindow(Integer maxResultWindow);
    indexName(String... indexNames);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

# Use cases

    /**
     * LambdaEsIndexWrapper constructor makes test case one: creating indexes, created by out-of-the-box methods
     */
    @Test
    public void testCreateIndex() {
        LambdaEsIndexWrapper<Document> wrapper = new LambdaEsIndexWrapper<>();
        // For simplicity's sake, keep the index name the same as the entity class name, lowercase.
        wrapper.indexName(Document.class.getSimpleName().toLowerCase());

        // here the title of the article mapped to keyword type (does not support word separation), the document content mapped to text type (support for word separation query)
        wrapper.mapping (Document::getTitle, FieldType.KEYWORD, 2.0f)
                .mapping(Document::getLocation, FieldType.GEO_POINT)
                .mapping(Document::getGeoLocation, FieldType.GEO_SHAPE)
                .mapping(Document::getContent, FieldType.TEXT, Analyzer.IK_SMART, Analyzer.IK_MAX_WORD);
        
        // set the sharding and replica information, can be defaulted
        wrapper.settings(3, 2);

        // set alias information, can be defaulted
        String aliasName = "daily";
        wrapper.createAlias(aliasName);

        // set the parent-child information, if there is no parent-child document relationship is not necessary to set
        wrapper.join("joinField", "document", "comment");

        // create an index
        boolean isOk = documentMapper.createIndex(wrapper);
        Assertions.assertTrue(isOk);
    }

    /**
     * LambdaEsIndexWrapper constructor makes test case two: create index, by custom map The most difficult to use but also the most flexible
     */
    @Test
    public void testCreateIndexByMap() {
        // demonstrate the creation of indexes by custom map, the most flexible, if option 1 can not meet this method
        LambdaEsIndexWrapper<Document> wrapper = new LambdaEsIndexWrapper<>();
        wrapper.indexName(Document.class.getSimpleName().toLowerCase());
        wrapper.settings(3, 2);
        Map<String, Object> map = new HashMap<>();
        Map<String, Object> prop = new HashMap<>();
        Map<String, String> field = new HashMap<>();
        field.put("type", FieldType.KEYWORD.getType());
        prop.put("this_is_field", field);
        map.put("properties", prop);
        wrapper.mapping(map);
        boolean isOk = documentMapper.createIndex(wrapper);
        Assertions.assertTrue(isOk);
    }

    /**
     * LambdaEsIndexWrapper constructor to make test case three: update index (not recommended, because index changes ES will rebuild the index, there are other better ways, see the section on index hosting later)
     */
    @Test
    public void testUpdateIndex() {
        // testUpdateIndex
        LambdaEsIndexWrapper<Document> wrapper = new LambdaEsIndexWrapper<>();
        // Specify which index to update
        String indexName = Document.class.getSimpleName().toLowerCase();
        wrapper.indexName(indexName);
        wrapper.mapping(Document::getCreator, FieldType.KEYWORD);
        wrapper.mapping(Document::getGmtCreate, FieldType.DATE);
        boolean isOk = documentMapper.updateIndex(wrapper);
        Assertions.assertTrue(isOk);
    }
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
Help us improve this document (opens new window)
Last update: 2025/05/11
Introduction of Wrapper
Select wrapper

← Introduction of Wrapper Select wrapper→

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