Description
We have this record stored in elastic search:
{ "_index": "INDEX_NAME", "_type": "_doc", "_id": "ID_VALUE", "_version": 44, "_score": 0, "_source": { "someAttribute": "someValue", "id": "someValue" } }
until now using spring data elasticsearch 3.x we were using class as this:
@Data @Document(indexName = INDEX_PREFIX + BLACKLIST) public class ClassName { @Id @JsonIgnore private String id; @JsonProperty("id") private String productId;
after upgrading to spring data elasticsearch 4.x which started using MappingElasticsearchConverter jackson anotations are useless and variable productId is null after reading from elastich search
when i try another trick like this:
@Data @Document(indexName = INDEX_PREFIX + BLACKLIST) public class ClassName { @Id private String elasticId; @Field("id") private String productId;
i get this error:
Exception while fetching data (INDEX_PATH) : Attempt to add id property private java.lang.String package.path.ClassName.elasticId but already have property private java.lang.String package.path.ClassName.Product.productId registered as id. Check your mapping configuration!
that's probably due to this part of code in org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchPersistentProperty
when any field named as "id" or "document" is set as id property, even there is @id anotation on some other field
this.isId = super.isIdProperty() || SUPPORTED_ID_PROPERTY_NAMES.contains(getFieldName());
is there any way how to read id property from elastic search by using spring data elastic serach 4.x ??