Skip to content

Map index name to document #2112

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
mirco-romagnoli opened this issue Mar 11, 2022 · 7 comments · Fixed by #2435
Closed

Map index name to document #2112

mirco-romagnoli opened this issue Mar 11, 2022 · 7 comments · Fixed by #2435
Assignees
Labels
status: worked on a contributor is working on this issue type: enhancement A general enhancement

Comments

@mirco-romagnoli
Copy link

We're using a date index name processor to point a document to the right index based on a document's date field value.
After saving the document we need to get it again from Elasticsearch to read some fields that are filled by an ingestion pipeline.
The issue is that after the save we don't know the index name where the document has been saved.
Could it be possible to add a @Index annotation that maps the document's index name on the Java field?

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

sothawo commented Mar 11, 2022

Not clear what mean with

a date index name processor to point a document to the right index

How are these index names constructed? Can't you search with a wildcard or index aliases?

@sothawo sothawo added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 11, 2022
@mirco-romagnoli
Copy link
Author

The processor points the document to an index with the structure yyyy-MM-dd, the date is determined by the value inside a field given as a parameter to the processor.
The issue here is that I have to directly get the document instead of searching for it, otherwise I have to wait for the translog to be flushed at each indexing request, which is not ideal.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 14, 2022
@sothawo
Copy link
Collaborator

sothawo commented Mar 14, 2022

even if it would be possible to write the index name to the document during writing, you would not have it back in the application. And even if so - if storing an entity in index-a and returning the information as result of the save or storing it in the entity on save would work - how would you later have this information to get the entity? That would mean to store the combination of entity id and index somewhere else.

And how would an @Index annotation help? What should be done with that?

@sothawo sothawo added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Mar 14, 2022
@mirco-romagnoli
Copy link
Author

mirco-romagnoli commented Mar 15, 2022

even if it would be possible to write the index name to the document during writing, you would not have it back in the application.

I have an ingestion pipeline associated to an index, when we put a document into that index instead of being written on that specific index it gets routed to another index based on the date value contained in the said document. I've successfully done that using the RestHighLevelClient and the actual index where the document has been written is included in the response.

That would mean to store the combination of entity id and index somewhere else.

Yes, and that's where an @Index annotation would be useful, the "_index" field of the response should be written in the annotated field of the mapped model.
For instance this is what I'm actually doing with a RestHighLevelClient to add a Model object to index my-index:

Model model = new Model();
Map<String, Object> map = objectMapper.convertValue(model, new TypeReference<>() {});
IndexRequest request = new IndexRequest("my-index");
request.source(map);
IndexResponse response = restHighLevelClient.index(request, RequestOptions.DEFAULT);
String index = response.getIndex();
String id = response.getId();

index value is not "my-index", instead is "my-index-yyyy-MM-dd" where the date is based on a field contained in the Model object.

By introducing an @Index annotation I could add an index field to the Model class, annotate it and index the document by doing the following:

Model model = new Model();
Model saved = elasticsearchOperations.save(model, IndexCoordinates.of("my-index"));

After that I expect that calling saved.getIndex() should return the same value contained in the index variable of the previous example.

@sothawo
Copy link
Collaborator

sothawo commented Mar 15, 2022

ok, I got it. Although I am not sure if @Index would be the right name, it might lead to the misconception that one could use this field to specify where the entity should be stored, we'll probably need a different name for that.

@sothawo sothawo added type: enhancement A general enhancement and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 15, 2022
@mirco-romagnoli
Copy link
Author

Yes, I agree with you. Maybe @ResponseIndex or @RetrievedIndex could be better?

@sothawo sothawo self-assigned this Jan 23, 2023
@sothawo sothawo added the status: worked on a contributor is working on this issue label Jan 23, 2023
sothawo added a commit to sothawo/spring-data-elasticsearch that referenced this issue Jan 25, 2023
sothawo added a commit that referenced this issue Jan 25, 2023
@sothawo
Copy link
Collaborator

sothawo commented Jan 25, 2023

@IndexedIndexName it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: worked on a contributor is working on this issue type: enhancement A general enhancement
Projects
None yet
3 participants