# How to add two \_type under same index. But both are having different Json data

**URL:** <https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142>\
**Category:** Elasticsearch\
**Created:** [August 6, 2018, 10:34am UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142 "2018-08-06T10:34:59Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sangeeth\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sangeeth\_Kumar](https://discuss.elastic.co/u/Sangeeth_Kumar)\
**Post date:** [August 6, 2018, 10:35am UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/1 "2018-08-06T10:35:00Z")

</div>

I'm working on Elastic search to store and retrieve schema less json's. I have created index called "index002", I tried to create document with two different \_type. Both having different json and some keys are still exists with different datatype.

Doc1:  
{  
"foo": "bar",  
"date": "23-3-90",  
"Type": "Open"  
}

Doc 2:

{  
"Name": "John",  
"date": "23-3-90",  
"Type": 2  
}

It throws an exception

ERROR:root:b'{"error":{"root\_cause":[{"type":"mapper\_parsing\_exception","reason":"failed to parse [Type]"}],"type":"mapper\_parsing\_exception","reason":"failed to parse [Type]","caused\_by":{"type":"number\_format\_exception","reason":"For input string: \"Open\""}},"status":400}'

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 6, 2018, 11:07am UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/2 "2018-08-06T11:07:02Z")

</div>

Your mapping probably has Type field as a number.  
That's why you can't index a String content in it.

---

<div class="post-metadata">

**Author:** ![Sangeeth\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sangeeth\_Kumar](https://discuss.elastic.co/u/Sangeeth_Kumar)\
**Post date:** [August 6, 2018, 11:15am UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/3 "2018-08-06T11:15:41Z")

</div>

Can i support any datatype for the field "Type"? Because the data could be in any datatype for my case. How could i index a document with different types?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 6, 2018, 11:27am UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/4 "2018-08-06T11:27:48Z")

</div>

You can only if you just want to store the field but not index it.  
In general, you could also just use text like:

```
"foo": "bar"

```

or

```
"foo": "4"
```

---

<div class="post-metadata">

**Author:** ![Sangeeth\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sangeeth\_Kumar](https://discuss.elastic.co/u/Sangeeth_Kumar)\
**Post date:** [August 6, 2018, 12:05pm UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/5 "2018-08-06T12:05:49Z")

</div>

Can i conclude that we are not able to map two data types for single field inside same index right?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 6, 2018, 12:08pm UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/6 "2018-08-06T12:08:29Z")

</div>

Yes. I believe we can say that.  
That's basically what we can say for most databases and most languages I guess.

But, you can use multifields may be to index the same value (ie a number) as both a number and a text.

But I'm curious about the use case. Why are you asking this?

---

<div class="post-metadata">

**Author:** ![Sangeeth\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sangeeth\_Kumar](https://discuss.elastic.co/u/Sangeeth_Kumar)\
**Post date:** [August 6, 2018, 1:19pm UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/7 "2018-08-06T13:19:13Z")

</div>

Thanks for your answer. I'm in the need of storing different JSON data in the same \_type. Because Im using schema less mongoDB as my database system earlier. Now I need to store some data's from mongo to elastic search via REST API.

In Mongo, we can store different JSON data in same collection as documents. Im trying to achieve the same here in ES.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 6, 2018, 1:33pm UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/8 "2018-08-06T13:33:06Z")

</div>

Storing and indexing are different things. That's why I asked in the first place.

Look at [https://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/enabled.html)

---

<div class="post-metadata">

**Author:** ![Sangeeth\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/50afbb/32.png) [@Sangeeth\_Kumar](https://discuss.elastic.co/u/Sangeeth_Kumar)\
**Post date:** [August 6, 2018, 1:38pm UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/9 "2018-08-06T13:38:00Z")

</div>

Yeah. Now we are in same way. Can i search or filter the stored data ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 6, 2018, 1:50pm UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/10 "2018-08-06T13:50:52Z")

</div>

No. If you don't index, you can't search.

---

<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:** [September 3, 2018, 1:50pm UTC](https://discuss.elastic.co/t/how-to-add-two-type-under-same-index-but-both-are-having-different-json-data/143142/11 "2018-09-03T13:50:56Z")

</div>

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