# Different documents types in same index

**URL:** <https://discuss.elastic.co/t/different-documents-types-in-same-index/129594>\
**Category:** Elasticsearch\
**Created:** [April 26, 2018, 6:23am UTC](https://discuss.elastic.co/t/different-documents-types-in-same-index/129594 "2018-04-26T06:23:44Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![agonzalez](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@agonzalez](https://discuss.elastic.co/u/agonzalez)\
**Post date:** [April 26, 2018, 6:23am UTC](https://discuss.elastic.co/t/different-documents-types-in-same-index/129594/1 "2018-04-26T06:23:44Z")

</div>

in 6.0 \_type is discontinued, but we can use custom field like "type" to index different types of objects in same index and then filter by that.

Is there any downside to this approach and store different documents types with differents fields in same index? or is better to use a different index per document type?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 26, 2018, 9:46am UTC](https://discuss.elastic.co/t/different-documents-types-in-same-index/129594/2 "2018-04-26T09:46:14Z")

</div>

> [@agonzalez](#):
>
> in 6.0 \_type is discontinued, but we can use custom field like "type" to index different types of objects in same index and then filter by that.

Yes.

> [@agonzalez](#):
>
> Is there any downside to this approach and store different documents types with differents fields in same index?

Yes, if they aren't the same shape/sort of data then you will run into problems with sparsity and the efficiency of your mappings.

> [@agonzalez](#):
>
> or is better to use a different index per document type?

If they are totally different structures, yes.

---

<div class="post-metadata">

**Author:** ![agonzalez](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@agonzalez](https://discuss.elastic.co/u/agonzalez)\
**Post date:** [April 26, 2018, 7:01pm UTC](https://discuss.elastic.co/t/different-documents-types-in-same-index/129594/3 "2018-04-26T19:01:27Z")

</div>

but metricbeat stores different structures for process utilization, flesystem ,network, psql etc in same metricbeat- index, doesnt it? why is not a problem there?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 27, 2018, 2:15am UTC](https://discuss.elastic.co/t/different-documents-types-in-same-index/129594/4 "2018-04-27T02:15:21Z")

</div>

Because the values are different but the structure is the same.

---

<div class="post-metadata">

**Author:** ![agonzalez](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@agonzalez](https://discuss.elastic.co/u/agonzalez)\
**Post date:** [May 4, 2018, 11:05am UTC](https://discuss.elastic.co/t/different-documents-types-in-same-index/129594/5 "2018-05-04T11:05:56Z")

</div>

in metricbeat structure of a filesystem document is not the same of a process document or network document

---

<div class="post-metadata">

**Author:** ![agonzalez](https://avatars.discourse-cdn.com/v4/letter/a/ba8739/32.png) [@agonzalez](https://discuss.elastic.co/u/agonzalez)\
**Post date:** [May 4, 2018, 11:13am UTC](https://discuss.elastic.co/t/different-documents-types-in-same-index/129594/6 "2018-05-04T11:13:00Z")

</div>

as i see metricbeat use the same root fields but then nested fields are totally different. Do you mean that if root fields are the same but not nested fields is fine to store in same index like these 2 docs from vmware module:

doc for virtual machines

> {  
> "@timestamp": "2017-10-12T08:05:34.853Z",  
> "beat": {  
> "hostname": "[host.example.com](http://host.example.com)",  
> "name": "[host.example.com](http://host.example.com)"  
> },  
> "metricset": {  
> "host": "[http://127.0.0.1:35887/sdk](http://127.0.0.1:35887/sdk)",  
> "module": "vsphere",  
> "name": "virtualmachine",  
> "rtt": 115  
> },  
> "vsphere": {  
> "virtualmachine": {  
> "cpu": {  
> "used": {  
> "mhz": 0  
> }  
> },  
> "host": "ha-host",  
> "memory": {  
> "free": {  
> "guest": {  
> "bytes": 33554432  
> }  
> },  
> "total": {  
> "guest": {  
> "bytes": 33554432  
> }  
> },  
> "used": {  
> "guest": {  
> "bytes": 0  
> },  
> "host": {  
> "bytes": 0  
> }  
> }  
> },  
> "name": "ha-host\_VM1"  
> }  
> }  
> }

doc for datastores:

> {  
> "@timestamp": "2017-10-12T08:05:34.853Z",  
> "beat": {  
> "hostname": "[host.example.com](http://host.example.com)",  
> "name": "[host.example.com](http://host.example.com)"  
> },  
> "metricset": {  
> "host": "[http://127.0.0.1:36937/sdk](http://127.0.0.1:36937/sdk)",  
> "module": "vsphere",  
> "name": "datastore",  
> "rtt": 115  
> },  
> "vsphere": {  
> "datastore": {  
> "capacity": {  
> "free": {  
> "bytes": 50021150720  
> },  
> "total": {  
> "bytes": 63918878720  
> },  
> "used": {  
> "bytes": 13897728000,  
> "pct": 21  
> }  
> },  
> "fstype": "local",  
> "name": "LocalDS\_0"  
> }  
> }  
> }

---

<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:** [June 1, 2018, 11:13am UTC](https://discuss.elastic.co/t/different-documents-types-in-same-index/129594/7 "2018-06-01T11:13:00Z")

</div>

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