-
Notifications
You must be signed in to change notification settings - Fork 1.3k
After upgrade to 4.x can't read property id from _source named (different value from _id) #1680
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This comes as you noticed from the fact that an id-property cannot only be defined by using the In your case this produces a clash as there are now 2 id properties. I'll fix this so that Spring Data Elasticsearch behaves like other spring data modules so that a property that has one of the supported names - either by the property itself or by a When this fix is in place you should use @Document(indexName = "custom-id")
public class CustomId {
@Id
@ReadOnlyProperty
private String elasticId;
@Field("id")
private String documentId;
// other properties, getter and setter
} By using |
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 ??
The text was updated successfully, but these errors were encountered: