惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
J
Java Code Geeks
L
LangChain Blog
V
V2EX
大猫的无限游戏
大猫的无限游戏
S
SegmentFault 最新的问题
博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
Jina AI
Jina AI
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Cloudflare Blog
博客园 - 司徒正美
B
Blog
G
Google Developers Blog
Stack Overflow Blog
Stack Overflow Blog
罗磊的独立博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
Engineering at Meta
Engineering at Meta
MyScale Blog
MyScale Blog
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog

博客园 - 正怒月神

windows 安装 openclaw docker-compose 启动 elk linux mysql 备份 maven 打包时优先选择本地仓库 nginx 部署2个相同的vue minio 设置IP MapStruct-plus cannot find converter from jenkins pipeline 发布 jar并运行 MapperStruct 嵌套模型中 List<> 转 List<String> Logstash docker发布 Docker 无法拉取 springmvc 多事务提交和回滚 springMvc 配置 UReport2 java 通过 microsoft graph 调用outlook(三) JPA Example 默认 join jackson.dataformat.xml 反序列化 对象中包含泛型 OR-TOOL 背包算法 解决JIRA、Confluence自动注销登录的问题 java 通过 microsoft graph 调用outlook(二)
Easy es问题总结
正怒月神 · 2024-07-22 · via 博客园 - 正怒月神

官网教程:https://www.easy-es.cn/pages/ac41f0/#settings

一 测试项目

1 pom

    <dependencies>
        <!-- 排除springboot中内置的es依赖,以防和easy-es中的依赖冲突-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.elasticsearch.client</groupId>
                    <artifactId>elasticsearch-rest-high-level-client</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.elasticsearch</groupId>
                    <artifactId>elasticsearch</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
        </dependency>
 
        <dependency>
            <groupId>org.dromara.easy-es</groupId>
            <artifactId>easy-es-boot-starter</artifactId>
        </dependency>
 
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

2 application.yml

# elasticsearch配置
easy-es:
  # 默认为true,若为false时,则认为不启用本框架
  enable: true 
  #填你的es连接地址
  address: 192.168.1.247:9200  

3 启动项:

添加扫描路径

@EsMapperScan("com.xxx.mapper_es")

4 domain_es

package com.xxx.domain_es;
 
import com.helka.bo.domain.gen.entity.BoSopContent;
import lombok.Data;
import org.dromara.easyes.annotation.IndexField;
import org.dromara.easyes.annotation.IndexId;
import org.dromara.easyes.annotation.IndexName;
import org.dromara.easyes.annotation.rely.Analyzer;
import org.dromara.easyes.annotation.rely.FieldType;
import org.dromara.easyes.annotation.rely.IdType;
 
 
@Data
@IndexName("bo_sop_content")
public class BoSopContentES {
    /**
     * ES的id(必须,否则会抛异常)
     */
    @IndexId(type= IdType.CUSTOMIZE)
    private String id;
    /**
     * sop的标题
     */
    @IndexField(fieldType = FieldType.TEXT, ignoreCase = true, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
    private String sop_title;
 
    /**
     * sop的内容
     */
    @IndexField(fieldType = FieldType.TEXT, ignoreCase = true, analyzer = Analyzer.IK_SMART, searchAnalyzer = Analyzer.IK_SMART)
    private String sop_content;
}

5 Mapper

import com.xxx.domain.gen.entity.BoSopContent;
import com.xxx.domain_es.BoSopContentES;
import org.dromara.easyes.core.core.BaseEsMapper;
 
/**
 * @author: Tyler
 * @create: 2024-07-19
 */
 
public interface BoSopContentESMapper extends BaseEsMapper<BoSopContentES> {
}

6 controller

package com.xxx.controller;
 
import com.xxx.domain_es.BoSopContentES;
import com.xxx.mapper_es.BoSopContentESMapper;
import lombok.RequiredArgsConstructor;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.elasticsearch.index.query.Operator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.List;
 
/**
 * @author: Tyler
 * @create: 2024-07-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/sopContentES")
public class BoSopContentESController {
    @Autowired
    BoSopContentESMapper sopMapper;
 
    /**
     * 查询索引下总数
     * @return
     */
    @GetMapping("/count")
    public Long count() {
        LambdaEsQueryWrapper<BoSopContentES> wrapper = new LambdaEsQueryWrapper<>();
        sopMapper.selectCount(wrapper);
        return sopMapper.selectCount(wrapper);
    }
 
    @GetMapping("/search")
    public List<BoSopContentES> search(String req) {
        LambdaEsQueryWrapper<BoSopContentES> wrapper = new LambdaEsQueryWrapper<>();
        //按照得分排序
        wrapper.multiMatchQuery(req
                , Operator.OR
                ,50
                ,BoSopContentES::getSop_title, BoSopContentES::getSop_content
            )
            .sortByScore();
        List<BoSopContentES> list1=sopMapper.selectList(wrapper);
 
        return list1;
    }
 
}

二 问题与解决

1 multiMatchQuery 查询与 kibana中不一致

这是由于minimumShouldMatch参数导致,easy-es默认为60,设置为50解决。

        //按照得分排序
        wrapper.multiMatchQuery(req
                , Operator.OR
                ,50
                ,BoSopContentES::getSop_title, BoSopContentES::getSop_content
            )
            .sortByScore();
        List<BoSopContentES> list1=sopMapper.selectList(wrapper);

2 org.dromara.easyes.common.exception.EasyEsException: no such method

es 实体创建id,es数据中无需修改

/**
     * ES的id(必须)
     */
    @IndexId(type= IdType.CUSTOMIZE)
    private String id;