使用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)

posted @ 2019-07-04 17:04  SJJAttractive  阅读(1129)  评论(0编辑  收藏  举报