# Defining a mapping for Join (ES 6.2.2) - CURL

**URL:** <https://discuss.elastic.co/t/defining-a-mapping-for-join-es-6-2-2-curl/124315>\
**Category:** Elasticsearch\
**Created:** [March 16, 2018, 2:37pm UTC](https://discuss.elastic.co/t/defining-a-mapping-for-join-es-6-2-2-curl/124315 "2018-03-16T14:37:32Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [March 16, 2018, 2:37pm UTC](https://discuss.elastic.co/t/defining-a-mapping-for-join-es-6-2-2-curl/124315/1 "2018-03-16T14:37:32Z")

</div>

What is the best mapping for a join between two documents?

Actually, i'm creating a data warehouse to stock my postgres data:

```
table: customer
column | type
---------------------------
id_customer | integer
name | varchar
email | varchar
enabled | char

table: order
column | type
---------------------------
id_order | integer
id_customer | integer (foreign key from customer)
value | numeric
finishied | char

```

How i create a mapping to this both documents?  
Because i will need search in orders when the customer (father) has the property enabled equal to 'Y'.

---

<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 16, 2018, 2:58pm UTC](https://discuss.elastic.co/t/defining-a-mapping-for-join-es-6-2-2-curl/124315/2 "2018-03-16T14:58:05Z")

</div>

Or what about a document like:

```auto
PUT orders/doc/1
{
  "value": 1,
  "finishied": true,
  "customer": {
    "name": "Joe Smith",
    "email": "joe@foo.bar",
    "enabled": true
  }
}

```

---

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [March 16, 2018, 3:34pm UTC](https://discuss.elastic.co/t/defining-a-mapping-for-join-es-6-2-2-curl/124315/3 "2018-03-16T15:34:26Z")

</div>

Hi @dadoonet.

After a customer update will be necessary reindex all the orders, and some customer can have a huge quantity of orders.

---

<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 16, 2018, 3:47pm UTC](https://discuss.elastic.co/t/defining-a-mapping-for-join-es-6-2-2-curl/124315/4 "2018-03-16T15:47:37Z")

</div>

> After a customer update will be necessary reindex all the orders

Yes.

> and some customer can have a huge quantity of orders.

How many? Like more than 1 million orders?  
How long would that take?

I mean that for sure you have to pay a price at some point.

Do you want to pay the price at index time? Or at search time?

---

<div class="post-metadata">

**Author:** ![TomTom](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tomtom/32/3676_2.png) [@TomTom](https://discuss.elastic.co/u/TomTom)\
**Post date:** [March 16, 2018, 4:05pm UTC](https://discuss.elastic.co/t/defining-a-mapping-for-join-es-6-2-2-curl/124315/5 "2018-03-16T16:05:40Z")

</div>

Thanks @dadoonet, your observation make all sense.

Is best pay the price at index time, whereas the client change occurs less frequently than orders.

---

<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 13, 2018, 4:18pm UTC](https://discuss.elastic.co/t/defining-a-mapping-for-join-es-6-2-2-curl/124315/6 "2018-04-13T16:18:44Z")

</div>

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