gpt4 book ai didi

spring-data - Spring data elasticsearch - 无法将非对象映射与对象映射合并

转载 作者:行者123 更新时间:2023-12-04 05:53:29 25 4
gpt4 key购买 nike

我在尝试使用实体类运行我的应用程序时遇到错误:

@Document(indexName = "index", type = "event")
public class Event {

...

@Field(type = FieldType.Date)
private Date dateTime;

...

}

错误是:

java.lang.IllegalArgumentException: Can't merge a non object mapping [dateTime] with an object mapping [dateTime]

为什么?

好的,那我注释掉这个@Field注解。所以,我有:

org.elasticsearch.index.mapper.MapperParsingException: object mapping for [dateTime] tried to parse field [dateTime] as object, but found a concrete value

当我做

curl -XPOST -H "Content-Type:application/json" http://localhost:8080/events -d '{ "dateTime": "2008-03-01T13:00:00.345"}'

最佳答案

我在具有 GeoPoint 属性的文档中遇到了类似的问题,其中不是使用“geo_point”映射属性,而是为纬度和经度设置类型“double”。经过几天的努力,我通过定义映射解决了问题:

if (!elasticsearchTemplate.indexExists(SEARCH_INDEX_NAME)) {
elasticsearchTemplate.createIndex(SEARCH_INDEX_NAME);
}
elasticsearchTemplate.refresh(PlaceIndex.class);
elasticsearchTemplate.putMapping(PlaceIndex.class);

就在开始索引项(和创建索引)之前:

 for (Place place : placePage.getContent()) {
IndexQuery indexQuery = new IndexQuery();

PlaceIndex placeIndex = new PlaceIndex();

placeIndex.setId(place.getId());
placeIndex.setName(place.getName());
placeIndex.setPosition(GeoPoint.fromPoint(new Point(place.getPosition().getY(),place.getPosition().getX())));


indexQuery.setId(placeIndex.getId().toString());
indexQuery.setObject(placeIndex);
indexQuery.setSource(elasticObjectMapper.writeValueAsString(placeIndex));

indexQuery.setIndexName(SEARCH_INDEX_NAME);
indexQuery.setType(PLACE_INDEX_TYPE);

queries.add(indexQuery);
if (counter % INDEX_COMMIT_SIZE == 0) {
elasticsearchTemplate.bulkIndex(queries);
queries.clear();
}
counter++;
}

有点晚了,但我希望这对你或其他人有帮助。

关于spring-data - Spring data elasticsearch - 无法将非对象映射与对象映射合并,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39446628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com