# Lookup in elasticsearch

**URL:** <https://discuss.elastic.co/t/lookup-in-elasticsearch/355229>\
**Category:** Elasticsearch\
**Created:** [March 12, 2024, 1:03pm UTC](https://discuss.elastic.co/t/lookup-in-elasticsearch/355229 "2024-03-12T13:03:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![hans\_hupe](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@hans\_hupe](https://discuss.elastic.co/u/hans_hupe)\
**Post date:** [March 12, 2024, 1:03pm UTC](https://discuss.elastic.co/t/lookup-in-elasticsearch/355229/1 "2024-03-12T13:03:08Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 12, 2024, 1:10pm UTC](https://discuss.elastic.co/t/lookup-in-elasticsearch/355229/2 "2024-03-12T13:10:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hans\_hupe](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@hans\_hupe](https://discuss.elastic.co/u/hans_hupe)\
**Post date:** [March 12, 2024, 1:31pm UTC](https://discuss.elastic.co/t/lookup-in-elasticsearch/355229/3 "2024-03-12T13:31:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 12, 2024, 1:35pm UTC](https://discuss.elastic.co/t/lookup-in-elasticsearch/355229/4 "2024-03-12T13:35:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 12, 2024, 2:16pm UTC](https://discuss.elastic.co/t/lookup-in-elasticsearch/355229/5 "2024-03-12T14:16:38Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-retrieving-fields.html#lookup-runtime-fields). 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 😉

---

<div class="post-metadata">

**Author:** ![hans\_hupe](https://avatars.discourse-cdn.com/v4/letter/h/ba9def/32.png) [@hans\_hupe](https://discuss.elastic.co/u/hans_hupe)\
**Post date:** [March 12, 2024, 2:48pm UTC](https://discuss.elastic.co/t/lookup-in-elasticsearch/355229/6 "2024-03-12T14:48:17Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 9, 2024, 2:48pm UTC](https://discuss.elastic.co/t/lookup-in-elasticsearch/355229/7 "2024-04-09T14:48:48Z")

</div>

Closed on April 9, 2024, 2:48pm UTC

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