# How to "Join" tables (Lookup)

**URL:** <https://discuss.elastic.co/t/how-to-join-tables-lookup/54804>\
**Category:** Elasticsearch\
**Created:** [July 6, 2016, 7:38am UTC](https://discuss.elastic.co/t/how-to-join-tables-lookup/54804 "2016-07-06T07:38:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NativAt](https://avatars.discourse-cdn.com/v4/letter/n/fbc32d/32.png) [@NativAt](https://discuss.elastic.co/u/NativAt)\
**Post date:** [July 6, 2016, 7:38am UTC](https://discuss.elastic.co/t/how-to-join-tables-lookup/54804/1 "2016-07-06T07:38:30Z")

</div>

I need to do "Join" between 2 indexes (tables) and preform a check on specific field on documents that exists in both indexes.

I want to add condition like "dateExpiry" below. Is it possible? Is there other alternatives?

```auto

GET cache-*/_search
{
  "query": {
    "bool": {
      "must_not": [
        {
          "query": {
            "terms": {
              "TagId": {
                "index": "domain_block-2016.06",
                "type": "cBlock",
                "id": "57692ef6ae8c50f67e8b45",
                "path": "TagId",
               "range" : {
               "dateExpiry" : {
                   "gte" : "20160705T12:00:00"
               }
              }
            }
          }
        }
      ]
    }
  } 
}

```

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [July 8, 2016, 5:32am UTC](https://discuss.elastic.co/t/how-to-join-tables-lookup/54804/2 "2016-07-08T05:32:45Z")

</div>

ES doesn't do joins. Documents need to be denormalized.

---

<div class="post-metadata">

**Author:** ![NativAt](https://avatars.discourse-cdn.com/v4/letter/n/fbc32d/32.png) [@NativAt](https://discuss.elastic.co/u/NativAt)\
**Post date:** [July 9, 2016, 10:43am UTC](https://discuss.elastic.co/t/how-to-join-tables-lookup/54804/3 "2016-07-09T10:43:55Z")

</div>

My documents are denormalized. Sometimes you just must do "Join" because it's not right to include unrelated data together in the same index for the matter of "denormalization". I think joins (or some other sort of lookups) are inevitable even in NoSQL databases. mongoDB is already stepping to this direction. Here: [Joins and Other Aggregation Enhancements Coming in MongoDB](https://www.mongodb.com/blog/post/joins-and-other-aggregation-enhancements-coming-in-mongodb-3-2-part-1-of-3-introduction).

---

<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:** [July 5, 2017, 10:36pm UTC](https://discuss.elastic.co/t/how-to-join-tables-lookup/54804/4 "2017-07-05T22:36:52Z")

</div>


