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

推荐订阅源

宝玉的分享
宝玉的分享
IT之家
IT之家
Stack Overflow Blog
Stack Overflow Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
腾讯CDC
P
Palo Alto Networks Blog
Spread Privacy
Spread Privacy
S
Schneier on Security
NISL@THU
NISL@THU
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
P
Proofpoint News Feed
T
Threatpost
Scott Helme
Scott Helme
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
I
Intezer
C
Check Point Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cyber Attacks, Cyber Crime and Cyber Security
S
Securelist
Security Latest
Security Latest
大猫的无限游戏
大猫的无限游戏
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
小众软件
小众软件
www.infosecurity-magazine.com
www.infosecurity-magazine.com
云风的 BLOG
云风的 BLOG
量子位
T
Tor Project blog
博客园 - 叶小钗
The Cloudflare Blog
Simon Willison's Weblog
Simon Willison's Weblog
T
Tailwind CSS Blog
W
WeLiveSecurity
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Security Affairs
罗磊的独立博客
Know Your Adversary
Know Your Adversary
Engineering at Meta
Engineering at Meta
G
Google Developers Blog
Help Net Security
Help Net Security
美团技术团队
P
Privacy International News Feed
The Hacker News
The Hacker News
Hugging Face - Blog
Hugging Face - Blog
MongoDB | Blog
MongoDB | Blog
N
Netflix TechBlog - Medium
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

博客园 - 正怒月神

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;