【问题标题】:Spring data elasticsearch - Can't merge a non object mapping with an object mappingSpring data elasticsearch - 无法将非对象映射与对象映射合并
【发布时间】:2017-01-19 16:10:11
【问题描述】:

我在尝试使用实体类运行我的应用时出错:

@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"}'

【问题讨论】:

  • 这个问题你解决了吗?
  • 不,只是把它扔掉了。

标签: spring-data spring-data-rest spring-data-elasticsearch


【解决方案1】:

我在具有 GeoPoint 属性的文档上遇到了类似的问题,它没有使用“geo_point”映射属性,而是为 lat 和 long 设置类型“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++;
        }

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    • 2016-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-19
    相关资源
    最近更新 更多