# How to get the match records based on two tables in same indices

**URL:** <https://discuss.elastic.co/t/how-to-get-the-match-records-based-on-two-tables-in-same-indices/355368>\
**Category:** Elasticsearch\
**Created:** [March 14, 2024, 7:38am UTC](https://discuss.elastic.co/t/how-to-get-the-match-records-based-on-two-tables-in-same-indices/355368 "2024-03-14T07:38:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tqvenkata](https://avatars.discourse-cdn.com/v4/letter/t/e5b9ba/32.png) [@Tqvenkata](https://discuss.elastic.co/u/Tqvenkata)\
**Post date:** [March 14, 2024, 7:38am UTC](https://discuss.elastic.co/t/how-to-get-the-match-records-based-on-two-tables-in-same-indices/355368/1 "2024-03-14T07:38:26Z")

</div>

Hi ,  
I need to get the output based on join condition tokenaccess.token with employee table and token access table (like sql join)  
please find the sample mapping and data

```auto
PUT joinindex/_mapping
{
  "properties": {
    "userid": {
      "type": "nested",
      "properties": {
        "user_id": {
          "type": "integer"
        }
      }
    },
    "tokenuseraccess": {
      "type": "nested",
      "properties": {
        "token": {
          "type": "text"
        }
      }
    },
    "age": {
      "type": "long"
    },
    "email": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "first_name": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "gender": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    },
    "id": {
      "type": "long"
    },
    "kilometer": {
      "type": "long"
    },
    "table": {
      "type": "text",
      "fields": {
        "keyword": {
          "type": "keyword",
          "ignore_above": 256
        }
      }
    }
  }
}

PUT joinindex/_doc/1
{
  "userid": {
    "user_id": [
      101,
      109
    ]
  },
  "tokenuseraccess": {
    "token": [
      102,
      103
    ]
  },
  "age": 16,
  "email": "john.doe@example.com",
  "first_name": "John",
  "gender": "Male",
  "id": 1,
  "kilometer": 15000,
  "table": "employee"
}

PUT joinindex/_doc/1
{
  "userid": {
    "user_id": [
      104,
      105
    ]
  },
  "tokenuseraccess": {
    "token": [
      104,
      105
    ]
  },
  "age": 27,
  "email": "test.doe@example.com",
  "first_name": "rajesh",
  "gender": "Male",
  "id": 1,
  "kilometer": 1500000,
  "table": "employee"
}

PUT joinindex/_doc/199
{
   "token": 102,
  "table": "tokenuseraccess"
}

```

---

<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 15, 2024, 7:45am UTC](https://discuss.elastic.co/t/how-to-get-the-match-records-based-on-two-tables-in-same-indices/355368/2 "2024-03-15T07:45:16Z")

</div>

Elasticsearch is not a relational database and does not support joins so I would recommend you denormalise the data. I also do not understand your example or what you mean when you refer to tables, as that is not a concept in Elasticsearch.

---

<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 12, 2024, 7:45am UTC](https://discuss.elastic.co/t/how-to-get-the-match-records-based-on-two-tables-in-same-indices/355368/3 "2024-04-12T07:45:22Z")

</div>

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