# Relating two Types in ES based on common field

**URL:** <https://discuss.elastic.co/t/relating-two-types-in-es-based-on-common-field/19189>\
**Category:** Elasticsearch\
**Created:** [August 11, 2014, 10:36am UTC](https://discuss.elastic.co/t/relating-two-types-in-es-based-on-common-field/19189 "2014-08-11T10:36:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paddy](https://avatars.discourse-cdn.com/v4/letter/p/77aa72/32.png) [@Paddy](https://discuss.elastic.co/u/Paddy)\
**Post date:** [August 11, 2014, 10:36am UTC](https://discuss.elastic.co/t/relating-two-types-in-es-based-on-common-field/19189/1 "2014-08-11T10:36:30Z")

</div>

Hi,

We have two types on different indexes. There is a situation where we need  
to query two types based on a common field.

We are looking for a single query to get the list of documents from both  
the types based on the common field.

Your help will be highly appreciated.

1. Type “location” in index “data”

POST /data/location/\_mapping

{

"data": {

```
  "mappings": {

     "location": {

       "properties": {

           "details": {

              "type": "string"

           },

           "ids": {

              "properties": {

                 "location_id": {

                    "type": "string",

                    "index": "not_analyzed"

                 }

              }

           },

           "status": {

              "type": "string"

           }

        }

     }

  }

```

}

}

1. Type “device” in index “inventory”

POST /inventory/device/\_mapping

{

"inventory": {

```
  "mappings": {

     "device": {

       "properties": {

           "details": {

              "type": "string"

           },

           "ids": {

              "properties": {

                 "location_id": {

                    "type": "string",

                    "index": "not_analyzed"

              },

```

"device\_id": {

```
   "type": "string",

                    "index": "not_analyzed"

```

}

```
              }

           },

           "status": {

              "type": "string"

           }

        }

     }

  }

```

}

}

The location\_id is common in both the types "location" and "device" , i.e.  
the value of "location\_id" present in location and device are same.

Is there any single query available to get the document from location and  
device types based on location\_id?

Thanks in advance.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/18956c1d-168d-4b88-af41-24f11543d7e8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/18956c1d-168d-4b88-af41-24f11543d7e8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 1:09am UTC](https://discuss.elastic.co/t/relating-two-types-in-es-based-on-common-field/19189/2 "2017-07-06T01:09:37Z")

</div>


