Skip to content

error while mapping _source.id #1764

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

Closed
lemosintelipost opened this issue Apr 6, 2021 · 6 comments
Closed

error while mapping _source.id #1764

lemosintelipost opened this issue Apr 6, 2021 · 6 comments
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@lemosintelipost
Copy link

I need to map the id field inside the elasticsearch _source field.
However, in all my attempts, the JPA parse returns the _id field to me.
as I have tens of millions of records in ES and it is not possible to arrive and go through all the docs correcting the name of the id field by another. So I need an option to map it, as it differs from the _id field.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 6, 2021
@sothawo
Copy link
Collaborator

sothawo commented Apr 6, 2021

can you provide an example Elasticsearch document and an entity class showing which fields you want to map to which property, and what should be the id for the entity?

btw, Spring Data Elasticsearch has nothing to do with JPA.

@lemosintelipost
Copy link
Author

public class Quote extends QuotationInput implements Serializable { 
    private String originZipCode;
    private String destinationZipCode;
    private String platform;
    private QuoteAdditionalInformation additionalInformation;
    private QuoteIdentification identification;

    @Id
    private String _id;

    // id inside _source
    @Field("id")
    private Long quoteId;
    private Integer clientId;
    private String clientName;

    private DateTime created;
    private List<QuoteDeliveryOption> deliveryOptions;
    private List<QuoteVolume> volumes;

    private Set<Integer> skuGroupIds;
    private double costOfGoods;
    private double totalWeight;
    private double cubicVolume;
    private boolean cached;

    @JsonProperty("@timestamp")
    private LocalDateTime timestamp;

    //não consta no payload de exemplo
    private String calculationLog;
    @JsonIgnore private List<QuoteDeliveryOption> originalDeliveryOptions;
}

@sothawo
Copy link
Collaborator

sothawo commented Apr 6, 2021

please check #1680 (comment)

@lemosintelipost
Copy link
Author

I implemented it this way, and I had this error:

nested exception is org.springframework.data.mapping.MappingException: Attempt to add id property private java.lang.String br.com.intelipost.ipquoteservices.infra.repository.Quote.documentId but already have property private java.lang.String br.com.intelipost.ipquoteservices.infra.repository.Quote.elasticId registered as id

I'm using version 4.1.7

@sothawo
Copy link
Collaborator

sothawo commented Apr 7, 2021

The change from #1680 is in the main (4.2) branch which will be released this month. But so would be any other change that would be implemented.

@sothawo
Copy link
Collaborator

sothawo commented Apr 16, 2021

version 4.2.0 was released a couple of days ago, with this version you can use the definitions from above.

@sothawo sothawo closed this as completed Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

3 participants