Lookup in elasticsearch

In relational databases I am used to refer to descriptive fields by a key, and then make a lookup in order to retrieve the description. So updating the description doesn't have an impact on the query logic.

How is this solved in elasticsearch? In the frontend I want to show the address of a customer, but I don't want to store it in the elasticsearch document as it can change. Is there a concept to only store the customer ID in the document and show the address based on the lookup?

I know I could do it on the frontend, but it would require some refactoring there, what is a best practice for this very common scenario?

Elasticsearch does not support query time joins, so the recommended approach is generally to denormalise and store the customer address with the customer in the document.

1 Like

So if the address changes, I would have to update all my documents?

Yes. How many documents would you need to update in such a scenario? How frequently does the address (or other fields) change?

I deeply agree with @Christian_Dahlqvist. Basically you need to forget what you learned and think "document" instead of relational technical implementation.

That being said, for some use cases, like "just display the text to the end user but not search for it", you can use lookups. See Retrieve a runtime field | Elasticsearch Guide [8.12] | Elastic. Note that will be slower.

But use that only if the advice Christian shared does not work for you. I mean: don't try to fix problems you think you might have as you take the risk of over engineering your project :wink:

Okay I see. A change can happen every few days or weeks. When I have a couple of millions of documents, I would have to update them if there is a change in the masterdata. I thought there might be a better way, but is will work.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.