Elasticsearch 教程_elasticsearch怎么启动

5.1.1 新增⽂档并随机⽣成id

5.1.2 新增⽂档并⾃定义id

5.2 查看⽂档

5.3 修改数据

5.4 删除数据

6 查询

6.1 基本查询

7 详情介绍


1 Lucene实现全⽂检索

1.1 项目部署

1.1.1 导入 pox.xml 依赖
<!-- 引入Lucene核心包及分词器包 -->
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-core</artifactId>
            <version>4.10.3</version>
        </dependency>
        <dependency>
            <groupId>org.apache.lucene</groupId>
            <artifactId>lucene-analyzers-common</artifactId>
            <version>4.10.3</version>
        </dependency>
        <!-- 单元测试 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <!-- 热部署 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <!-- Lombok工具 -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- IK中文分词器 -->
        <dependency>
            <groupId>com.janeluo</groupId>
            <artifactId>ikanalyzer</artifactId>
            <version>2012_u6</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
1.1.2 配置 application.yml 文件
server:
  port: 9000
Spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/es_db?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
    username: root
    password: 123

# 开启驼峰命名匹配映射
mybatis:
  configuration:
    map-underscore-to-camel-case: true

1.1.3 创建实体类时可能出现的问题

说明:SpringBoot项⽬启动提示This primary key of “id” is primitive !不建议如此请使⽤包装类in Class: “com.yx.pojo.JobInfo”。

1.解决⽅法:

使⽤包装类替换基本数据类型。将id字段封装成Long类型或Integer类型,具体选择什么类型取 决于数据库中该id字段的类型。

2.警告原因:

如果⽤long的话id的默认值会是0,会出现⼀些问题,⽐如在MyBatis-Plus使⽤save()⽅法时就 不能使⽤算法⽣成id了,这样会⽣成id为0的数据,如果有唯⼀或者主键约束的话,下⼀次⽣成就会报错。

1.2 创建索引

  • 25
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要合理创建 Elasticsearch(ES)索引,需要考虑以下几个方面: 1. 确定索引的名称:ES中的索引名称应该简洁明了,能够清楚地表达索引的用途或内容。 2. 确定索引的字段:确定需要存储的字段以及字段的类型。在创建索引时,需要指定每个字段的映射类型,包括文本、数字、日期等等。 3. 确定分片和副本:根据数据量和查询负载来确定分片和副本的数量,以实现最佳性能和可用性。 4. 配置索引分析器:ES中的分析器用于将文本字段拆分成单词,并将这些单词标准化以便于搜索。可以根据需要配置合适的分析器。 5. 配置索引设置:根据需要配置索引的相关设置,包括存储大小、写入限制、刷新间隔等等。 6. 优化索引性能:可以通过调整索引缓存、启用压缩、设置合理的索引刷新间隔等方式来优化索引性能。 创建索引的基本语法如下: ``` PUT /索引名称 { "settings": { "number_of_shards": 分片数量, "number_of_replicas": 副本数量 }, "mappings": { "properties": { "字段名称": { "type": "字段类型" } } } } ``` 例如,创建一个名为“my_index”的索引,包含“title”和“content”两个字段,其中“title”为文本类型,而“content”为长文本类型,可以使用以下命令: ``` PUT /my_index { "settings": { "number_of_shards": 5, "number_of_replicas": 1 }, "mappings": { "properties": { "title": { "type": "text" }, "content": { "type": "text", "analyzer": "english" } } } } ``` 以上是创建索引的基本步骤和语法,根据实际需求,可以进一步配置索引的设置和优化性能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值