# Creating a "join" mapping between two indexes using lookup

**URL:** <https://discuss.elastic.co/t/creating-a-join-mapping-between-two-indexes-using-lookup/345204>\
**Category:** Elasticsearch\
**Created:** [October 17, 2023, 12:10pm UTC](https://discuss.elastic.co/t/creating-a-join-mapping-between-two-indexes-using-lookup/345204 "2023-10-17T12:10:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ugurcandede](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ugurcandede/32/126592_2.png) [@ugurcandede](https://discuss.elastic.co/u/ugurcandede)\
**Post date:** [October 17, 2023, 12:10pm UTC](https://discuss.elastic.co/t/creating-a-join-mapping-between-two-indexes-using-lookup/345204/1 "2023-10-17T12:10:33Z")

</div>

when I make following request. I got the following error.

```auto
PUT /develop_tickets_dev/_mapping
{
  "properties": {
    "fieldMap": {
      "type": "nested",
      "properties": {
        "ts.requester": {
          "type": "object",
          "properties": {
            "value": {
              "type": "long"
            },
            "lookup": {
              "type": "object",
              "properties": {
                "index": "develop_users_dev",
                "type": "user",
                "path": "id"
              }
            }
          }
        }
      }
    }
  }
}

```

Here is the error:

```json
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "Expected map for property [fields] on field [path] but got a class java.lang.String"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "Failed to parse mapping: Expected map for property [fields] on field [path] but got a class java.lang.String",
    "caused_by": {
      "type": "mapper_parsing_exception",
      "reason": "Expected map for property [fields] on field [path] but got a class java.lang.String"
    }
  },
  "status": 400
}

```

My mapping is as follows:

```json
{
  "mappings": {
    "properties": {
      "email": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "fullName": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "id": {
        "type": "long"
      }
    }
  }
}

```

what should be the correct lookup object in the request?

---

<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:** [October 17, 2023, 1:08pm UTC](https://discuss.elastic.co/t/creating-a-join-mapping-between-two-indexes-using-lookup/345204/2 "2023-10-17T13:08:01Z")

</div>

Welcome!

What is that? Where is this coming from? I mean, which documentation is telling you this example?

```
          "properties": {
            "index": "develop_users_dev",
            "type": "user",
            "path": "id"
          }

```

---

<div class="post-metadata">

**Author:** ![ugurcandede](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ugurcandede/32/126592_2.png) [@ugurcandede](https://discuss.elastic.co/u/ugurcandede)\
**Post date:** [October 18, 2023, 8:41am UTC](https://discuss.elastic.co/t/creating-a-join-mapping-between-two-indexes-using-lookup/345204/3 "2023-10-18T08:41:26Z")

</div>

Hi, Google Bard created the mapping I was trying to create. I could not find a similar structure in my search. When I asked Bard to give a reference for the query, it referenced the address "[Elasticsearch Documentation - Mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)".

```markdown
Here is a summary of the information I used in this particular case:
 * Matches the value of the field "fieldMap.ts.requester.value" against the "id" field in the "develop_users_dev" index by setting the "relation" property to "lookup".
 * Setting the "path" property to "develop_users_dev/id" specifies the path to the "id" field in the "develop_users_dev" index.

```

* * *

I wanted to ask, just to be sure.

What I want to do is add a mapping called "lookup" to a field in the "develop\_tickets\_dev" index to be able to fetch the user's fields by associating them with a document in the "develop\_users\_dev" index.

---

<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:** [October 18, 2023, 9:38am UTC](https://discuss.elastic.co/t/creating-a-join-mapping-between-two-indexes-using-lookup/345204/5 "2023-10-18T09:38:22Z")

</div>

Actually we do have a lookup at search time. It's a bit limited but could help. See [Retrieve a runtime field | Elasticsearch Guide [8.10] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-retrieving-fields.html#lookup-runtime-fields)

I did a demo of this 2 weeks ago for the elastic daily bytes 😉

> **[Runtime fields - Daily Elastic Byte S05E04](https://www.youtube.com/live/HpjxfS5rrhI?si=yVO1w3aFZpcjplmC&t=447)**
>
> Daily Elastic Byte Season 05: SearchFor three weeks we will dive into a different topic related to the Search space every day before lunch in the CEST/EST ti...

---

<div class="post-metadata">

**Author:** ![ugurcandede](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ugurcandede/32/126592_2.png) [@ugurcandede](https://discuss.elastic.co/u/ugurcandede)\
**Post date:** [October 18, 2023, 11:22am UTC](https://discuss.elastic.co/t/creating-a-join-mapping-between-two-indexes-using-lookup/345204/6 "2023-10-18T11:22:48Z")

</div>

As you said, although "runtime\_mapping" has limited use, it solved my problem at the end of the day.  
Thanks David.

---

<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:** [November 15, 2023, 11:22am UTC](https://discuss.elastic.co/t/creating-a-join-mapping-between-two-indexes-using-lookup/345204/7 "2023-11-15T11:22:51Z")

</div>

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