使用elasticsearch时所遇问题

问题一:使用@Field注解为id指定type时,一直都是Keyword

像我指定属性id的type值为Long或者为Text,都无济于事

@Field(type = FieldType.Long)
private Long id;

@Field(type = FieldType.Text)
private Long id;

解决:不使用注解@Field,在新增文档时会自动创建类型下属性的值。

问题二:同一索引下,不同类型中的属性名相同,属性名下的参数一定得相同,否则启动报入下错

Mapper for [brandName] conflicts with existing mapping in other types:[mapper [brandName] has different [store] values]

翻译为:[brandname]的映射器与其他类型中的现有映射冲突:[映射器[brandname]具有不同的[store]值]

看price这个属性,type为integer,如果同一索引下另一个type下的也有个属性为price,那么这个属性的price的"type"一定得是“integer”,不然会启动报错

例子:

同一索引erp

type = stockInfo

import java.util.Date;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "erp",type="stockInfo")
public class StockInfoResult {

    private Long id;
    
    @Field(type = FieldType.Float)
    private Date price;
}

type = itemInfo

import java.util.Date;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName="erp",type="itemInfo")
public class ItemInfoResult{

    private Long id;
    
    @Field(type = FieldType.Double)
    private Date price;
}

启动报错:

Caused by: java.lang.IllegalArgumentException: mapper [price] cannot be changed from type [double] to [float]

 只能改为相同的类型,或者使用不同的属性表示(6.x中一个索引下只能有一个类型,我的版本是5.6.15)

转载于:https://www.cnblogs.com/sjj162/p/11133462.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用 Elasticsearch SQL 插件,您需要先确保您已经安装了 Elasticsearch 7.1.1 版本。然后,按照以下步骤进行操作: 1. 安装 Elasticsearch SQL 插件: - 打开终端或命令提示符窗口。 - 运行以下命令安装 Elasticsearch SQL 插件: ``` ./bin/elasticsearch-plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/7.1.1.0/elasticsearch-sql-7.1.1.0.zip ``` - 安装完成后,重启 Elasticsearch 以使插件生效。 2. 使用 Elasticsearch SQL: - 打开终端或命令提示符窗口。 - 进入 Elasticsearch 的安装目录。 - 运行以下命令以启动 Elasticsearch SQL 查询: ``` ./bin/elasticsearch-sql-cli ``` - 您将进入 Elasticsearch SQL 的命令行界面。 - 现在,您可以开始使用 SQL 语法来查询 Elasticsearch 数据。 例如,您可以运行以下命令来执行一个简单的 SELECT 查询: ``` SELECT * FROM your_index_name WHERE your_field_name = 'your_value' ``` 注意:在上述查询中,`your_index_name` 是您要查询的索引名称,`your_field_name` 是您要查询的字段名称,`your_value` 是您要匹配的字段值。 这样,您就可以使用 Elasticsearch SQL 插件来执行 SQL 查询并检索 Elasticsearch 中的数据了。请记住,Elasticsearch SQL 插件提供了一种方便的方式来使用 SQL 语法进行查询,但它可能不适用于所有类型的查询,特别是复杂的查询。因此,在使用插件时,请确保您了解其使用限制和适用场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值