# Multiple documents types being combined into one source

**URL:** <https://discuss.elastic.co/t/multiple-documents-types-being-combined-into-one-source/5285>\
**Category:** Elasticsearch\
**Created:** [August 30, 2011, 9:27pm UTC](https://discuss.elastic.co/t/multiple-documents-types-being-combined-into-one-source/5285 "2011-08-30T21:27:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![danpolites](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danpolites/32/2136_2.png) [@danpolites](https://discuss.elastic.co/u/danpolites)\
**Post date:** [August 30, 2011, 9:27pm UTC](https://discuss.elastic.co/t/multiple-documents-types-being-combined-into-one-source/5285/1 "2011-08-30T21:27:45Z")

</div>

I'm indexing two different documents (building and customer) very  
close to one another and I end up with two sources from different  
types being combined into the source of the customer type. Any idea as  
to why this is happening? I put a few line returns between the two  
sources below for clarity. I am using version 0.17.4 of the Java API.

curl -XGET '[http://localhost:9200/xyz.customer](http://localhost:9200/xyz.customer).  
4e52562703640801a2ba1894/customer/4e52562703640801a2ba1894?pretty=1'  
{  
"\_index" : "xyz.customer.4e52562703640801a2ba1894",  
"\_type" : "customer",  
"\_id" : "4e52562703640801a2ba1894",  
"\_version" : 13,  
"exists" : true, "\_source" :  
// THE BUILDING SOURCE  
{"id":"4e5d51d2036410ce0107b7e3","customerId":"4e52562703640801a2ba1894","customerName":"Test  
Organization  
1","name":"test","demographics":null,"dateCreated":"2011-08-30T21:10:42.846Z","lastUpdated":"2011-08-30T21:10:42.846Z","publicTags":"","enabled":true,"address":"test  
test, test test"}

// THE CUSTOMER SOURCE  
{"id":"4e52562703640801a2ba1894","name":"Test Organization  
1","dateCreated":"2011-08-22T13:14:15.514Z","lastUpdated":"2011-08-22T13:14:15.514Z","type":"xyztype","numberOfUsers":  
3,"numberOfBuildings":13,"enabled":true}

}

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 30, 2011, 9:38pm UTC](https://discuss.elastic.co/t/multiple-documents-types-being-combined-into-one-source/5285/2 "2011-08-30T21:38:32Z")

</div>

How are you indexing the data? Most of the times, it comes from the fact  
that XContentBuilder(s) are cached on a thread for better perf, so using two  
of those in two indexing requests before executing them can result in that.  
If you use it, see if using XContentFactory#safeJsonBuilder fixes it.

On Wed, Aug 31, 2011 at 12:27 AM, danpolites [dpolites@gmail.com](mailto:dpolites@gmail.com) wrote:

> I'm indexing two different documents (building and customer) very  
> close to one another and I end up with two sources from different  
> types being combined into the source of the customer type. Any idea as  
> to why this is happening? I put a few line returns between the two  
> sources below for clarity. I am using version 0.17.4 of the Java API.
> 
> curl -XGET '[http://localhost:9200/xyz.customer](http://localhost:9200/xyz.customer).  
> 4e52562703640801a2ba1894/customer/4e52562703640801a2ba1894?pretty=1'  
> {  
> "\_index" : "xyz.customer.4e52562703640801a2ba1894",  
> "\_type" : "customer",  
> "\_id" : "4e52562703640801a2ba1894",  
> "\_version" : 13,  
> "exists" : true, "\_source" :  
> // THE BUILDING SOURCE
> 
> {"id":"4e5d51d2036410ce0107b7e3","customerId":"4e52562703640801a2ba1894","customerName":"Test  
> Organization
> 
> 1","name":"test","demographics":null,"dateCreated":"2011-08-30T21:10:42.846Z","lastUpdated":"2011-08-30T21:10:42.846Z","publicTags":"","enabled":true,"address":"test  
> test, test test"}
> 
> // THE CUSTOMER SOURCE  
> {"id":"4e52562703640801a2ba1894","name":"Test Organization
> 
> 1","dateCreated":"2011-08-22T13:14:15.514Z","lastUpdated":"2011-08-22T13:14:15.514Z","type":"xyztype","numberOfUsers":  
> 3,"numberOfBuildings":13,"enabled":true}
> 
> }

---

<div class="post-metadata">

**Author:** ![danpolites](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danpolites/32/2136_2.png) [@danpolites](https://discuss.elastic.co/u/danpolites)\
**Post date:** [August 30, 2011, 10:22pm UTC](https://discuss.elastic.co/t/multiple-documents-types-being-combined-into-one-source/5285/3 "2011-08-30T22:22:24Z")

</div>

I was using the XContentFactory#jsonBuilder and switching to the  
safeJsonBuilder solved my issue. Is there anything to watch out for  
when using the safeJsonBuilder?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 31, 2011, 11:15am UTC](https://discuss.elastic.co/t/multiple-documents-types-being-combined-into-one-source/5285/4 "2011-08-31T11:15:13Z")

</div>

Nothing to watch when using safeJsonBuilder as it does no caching.

On Wed, Aug 31, 2011 at 1:22 AM, danpolites [dpolites@gmail.com](mailto:dpolites@gmail.com) wrote:

> I was using the XContentFactory#jsonBuilder and switching to the  
> safeJsonBuilder solved my issue. Is there anything to watch out for  
> when using the safeJsonBuilder?

---

<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, 3:55am UTC](https://discuss.elastic.co/t/multiple-documents-types-being-combined-into-one-source/5285/5 "2017-07-06T03:55:30Z")

</div>

Closed on July 6, 2017, 3:55am UTC


