Creating a "join" mapping between two indexes using lookup

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

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:

{
  "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:

{
  "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?

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"
          }

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".

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.

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

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

3 Likes

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

2 Likes

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