# Inner Join Using Federate

**URL:** <https://community.siren.io/t/inner-join-using-federate/226>\
**Category:** Siren Federate (Elasticsearch Plugin)\
**Created:** [April 9, 2020, 4:01pm UTC](https://community.siren.io/t/inner-join-using-federate/226 "2020-04-09T16:01:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thaher\_majeed](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.siren.io/thaher_majeed/32/136_2.png) [@thaher\_majeed](https://community.siren.io/u/thaher_majeed)\
**Post date:** [April 9, 2020, 4:01pm UTC](https://community.siren.io/t/inner-join-using-federate/226/1 "2020-04-09T16:01:54Z")

</div>

Hi Guys,  
I am trying to filter a result from indexA using a record from lookup indexB. ie the foreign key from document in indexA should match with a field inside a record in indexB. Where i can specify the id of record. And then match with id of a specific field and foreign key.

```
	{"join" : {
    			"indices" : ["indexB"],
    			"on" : ["userId", "<StaticRecordID>.id"], 
    			"request" : {
    				 "query" : {
    				 "bool": {
        					 "must" :[ {"term" : {
        								  "someCondition" : true
        								 }}
    								 ]
        						}
        					}
    			 }
    }

```

I need to match foreign key of document in indexA (userId) with field id inside a record of static id say 121

---

<div class="post-metadata">

**Author:** ![renaud.delbru](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.siren.io/renaud.delbru/32/13_2.png) [@renaud.delbru](https://community.siren.io/u/renaud.delbru)\
**Post date:** [April 10, 2020, 7:40am UTC](https://community.siren.io/t/inner-join-using-federate/226/2 "2020-04-10T07:40:47Z")

</div>

Hi,

I am not sure I fully understand the question,  
but if you want to restrict the documents of index B to something very specific, e.g., a record with a `static_id` equals to 121, then you can add a filter clause to the nested request. See below.  
You can then use the join clause in order to filter documents from index A based on documents from index B with a matching correspondence between the foreign key `userId` and the `id`,

```auto
{
  "join": {
    "indices": [
      "indexB"
    ],
    "on": [
      "userId",
      "id"
    ],
    "request": {
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "static_id": 121
              }
            },
            {
              "term": {
                "someCondition": true
              }
            }
          ]
        }
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![thaher\_majeed](https://yyz2.discourse-cdn.com/flex032/user_avatar/community.siren.io/thaher_majeed/32/136_2.png) [@thaher\_majeed](https://community.siren.io/u/thaher_majeed)\
**Post date:** [April 11, 2020, 5:45am UTC](https://community.siren.io/t/inner-join-using-federate/226/3 "2020-04-11T05:45:02Z")

</div>

@renaud.delbru No, I wanted to restrict based on a field out side the joined records. And i have solved it by reversing the way I am indexing the lookup index.So that the static ID comes inside the joined records. Thanks anyways.
