# Query multiple document types

**URL:** https://discuss.elastic.co/t/query-multiple-document-types/71086
**Category:** Kibana
**Created:** [January 10, 2017, 1:08pm UTC](https://discuss.elastic.co/t/query-multiple-document-types/71086 "2017-01-10T13:08:23Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![JohnG](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@JohnG](https://discuss.elastic.co/u/JohnG)
#### Post date: [January 10, 2017, 1:08pm UTC](https://discuss.elastic.co/t/query-multiple-document-types/71086/1 "2017-01-10T13:08:23Z")

</div>

Hi,

I'm at the very start with ELK and have a question. I have 1 index that contains 2 document types, the first type contains the main info and the second contains multiple entries that relate to a key value in the first.

I can't see how I can query to extract data from both documents?

Any help is much appreciated

---

<div class="post-metadata">

### Author: ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)
#### Post date: [January 10, 2017, 2:57pm UTC](https://discuss.elastic.co/t/query-multiple-document-types/71086/2 "2017-01-10T14:57:23Z")

</div>

Hi @JohnG,

performing queries across multiple documents is only supported in a limited fashion in elasticsearch, because it is built to support a horizontal scaling strategy. Nevertheless, there are the `has_child`, `has_parent` and `parent_id` queries, which might help you - depending on your document structure. See the documentation regarding [joining queries](https://www.elastic.co/guide/en/elasticsearch/reference/current/joining-queries.html) for details.

---

<div class="post-metadata">

### Author: ![JohnG](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@JohnG](https://discuss.elastic.co/u/JohnG)
#### Post date: [January 10, 2017, 3:24pm UTC](https://discuss.elastic.co/t/query-multiple-document-types/71086/3 "2017-01-10T15:24:25Z")

</div>

Thanks for the response Felix.

I have found some mapping instructions (here is an example).

PUT /company  
{  
"mappings": {  
"branch": {},  
"employee": {  
"\_parent": {  
"type": "branch"  
}  
}  
}  
}

Where would this code go? in the elasticsearch.yml?

Thanks.

---

<div class="post-metadata">

### Author: ![weltenwort](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weltenwort/32/53885_2.png) [@weltenwort](https://discuss.elastic.co/u/weltenwort)
#### Post date: [January 10, 2017, 3:39pm UTC](https://discuss.elastic.co/t/query-multiple-document-types/71086/4 "2017-01-10T15:39:37Z")

</div>

To define mappings you have to send `PUT` requests like these to the Elasticsearch server after it has been started. You could to that using `curl`, for example:

`$ curl -X PUT 'http://localhost:9200/company' -d '{"mappings": {...}}'`

The [documentation on the indices api](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html) offers more examples.

---

<div class="post-metadata">

### Author: ![JohnG](https://avatars.discourse-cdn.com/v4/letter/j/f4b2a3/32.png) [@JohnG](https://discuss.elastic.co/u/JohnG)
#### Post date: [January 10, 2017, 4:23pm UTC](https://discuss.elastic.co/t/query-multiple-document-types/71086/5 "2017-01-10T16:23:50Z")

</div>

Ah, ok.

Many thanks 🙂

---

<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: [February 7, 2017, 4:24pm UTC](https://discuss.elastic.co/t/query-multiple-document-types/71086/6 "2017-02-07T16:24:00Z")

</div>

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