# Query behavior for an index with multiple document types and mapping per doc type, bug?

**URL:** <https://discuss.elastic.co/t/query-behavior-for-an-index-with-multiple-document-types-and-mapping-per-doc-type-bug/9599>\
**Category:** Elasticsearch\
**Created:** [November 7, 2012, 3:36pm UTC](https://discuss.elastic.co/t/query-behavior-for-an-index-with-multiple-document-types-and-mapping-per-doc-type-bug/9599 "2012-11-07T15:36:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Garth](https://avatars.discourse-cdn.com/v4/letter/g/ba9def/32.png) [@Garth](https://discuss.elastic.co/u/Garth)\
**Post date:** [November 7, 2012, 3:36pm UTC](https://discuss.elastic.co/t/query-behavior-for-an-index-with-multiple-document-types-and-mapping-per-doc-type-bug/9599/1 "2012-11-07T15:36:09Z")

</div>

Not sure if there is a bug or DHE ( Developer Headspace Error ) in how the  
index handles  
multiple mappings in an index. In short I have two document types,  
"docType" with explicit  
mapping such that "docType" is mapped differently.  
If the type is "string" data is returned as expected. If it's "integer" I  
have to change how  
I query it to get the correct result.

Running on ES: 0.19.8

Here is my example:

Creating the index:

curl -XDELETE '[http://localhost:9200/multi\_documents](http://localhost:9200/multi_documents)'  
curl -XPUT '[http://localhost:9200/multi\_documents](http://localhost:9200/multi_documents)'  
curl -XPUT '[http://localhost:9200/multi\_documents/ferret/\_mapping](http://localhost:9200/multi_documents/ferret/_mapping)' -d '{  
"ferret":{  
"properties":{  
"docType":{ "type":"string" },  
"ident\_ferret" : { "type" : "integer" }  
}  
}  
}'  
curl -XPUT '[http://localhost:9200/multi\_documents/wombat/\_mapping](http://localhost:9200/multi_documents/wombat/_mapping)' -d '{  
"wombat":{  
"properties" :{  
"docType" : { "type" : "integer" },  
"ident\_wombat" : { "type" : "integer" }  
}  
}  
}'

load data:

curl -XPOST '[http://localhost:9200/multi\_documents/ferret/ferret-001](http://localhost:9200/multi_documents/ferret/ferret-001)' -d '{  
"doc\_id":"ferret-001",  
"docType" : "ferret",  
"entityType" : "animal",  
"ident\_ferret" : 200  
}'  
curl -XPOST '[http://localhost:9200/multi\_documents/wombat/wombat-001](http://localhost:9200/multi_documents/wombat/wombat-001)' -d '{  
"doc\_id":"wombat-001",  
"docType" : 10,  
"entityType": "animal",  
"ident\_wombat" : 100  
}'

Query the index with field of same type in both document types ( SUCCESS ).  
Both  
"ferret" and "wombat" document are returned.

curl -XGET '[http://localhost:9200/multi\_documents/\_search](http://localhost:9200/multi_documents/_search)' -d '{  
"size":100,  
"query":{"field":{"entityType":"animal"}}  
}'

Query across the document types ( by not defining them in URL ) asking for  
a docType that is string ( SUCCESS ).  
It returns the "ferret" document.

curl -XGET '[http://localhost:9200/multi\_documents/\_search](http://localhost:9200/multi_documents/_search)' -d '{  
"size":100,  
"query":{"field":{"docType":"ferret"}}  
}'

Query across the document types ( by not defining them in URL ) asking for  
a docType that is integer ( FAIL ). Should be getting "wombat" document  
returned.  
curl -XGET '[http://localhost:9200/multi\_documents/\_search](http://localhost:9200/multi_documents/_search)' -d '{  
"size":100,  
"query":{"field":{"docType":10}}  
}'

To make the above query that fails to work, I have to explicitly define the  
documentType in the field ( SUCCESS ).  
It returns the "wombat" document.  
curl -XGET '[http://localhost:9200/multi\_documents/\_search](http://localhost:9200/multi_documents/_search)' -d '{  
"size":100,  
"query":{"field":{"wombat.docType":10}}  
}'

Try the query above but specify the document type in URL ( FAIL ). Should  
be getting  
"wombat" document returned.  
curl -XGET '[http://localhost:9200/multi\_documents/wombat/\_search](http://localhost:9200/multi_documents/wombat/_search)' -d '{  
"size":100,  
"query":{"field":{"docType":10}}  
}'

--

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [November 7, 2012, 3:49pm UTC](https://discuss.elastic.co/t/query-behavior-for-an-index-with-multiple-document-types-and-mapping-per-doc-type-bug/9599/2 "2012-11-07T15:49:16Z")

</div>

Hello Garth,

This seems to be a "known issue", because all the types within the  
same ES index (actually, within the same shard) will end up in the  
same Lucene index. Take a look here for some more info about this:

> **[Elastic — The Search AI Company](https://www.elastic.co)**
>
> Power insights and outcomes with The Elastic Search AI Platform. See into your data and find answers that matter with enterprise solutions designed to help you accelerate time to insight. Try Elastic ...

My understanding is that in your case, ES has no [good] way to know  
which mapping type you're referring to when you specify "docType" as a  
field within your query. Unless you specify it explicitly, like you  
did with wombat.docType.

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Wed, Nov 7, 2012 at 5:36 PM, Garth [ghershfield.bah@gmail.com](mailto:ghershfield.bah@gmail.com) wrote:

> Not sure if there is a bug or DHE ( Developer Headspace Error ) in how the  
> index handles  
> multiple mappings in an index. In short I have two document types, "docType"  
> with explicit  
> mapping such that "docType" is mapped differently.  
> If the type is "string" data is returned as expected. If it's "integer" I  
> have to change how  
> I query it to get the correct result.
> 
> Running on ES: 0.19.8
> 
> Here is my example:
> 
> Creating the index:
> 
> curl -XDELETE '[http://localhost:9200/multi\_documents](http://localhost:9200/multi_documents)'  
> curl -XPUT '[http://localhost:9200/multi\_documents](http://localhost:9200/multi_documents)'  
> curl -XPUT '[http://localhost:9200/multi\_documents/ferret/\_mapping](http://localhost:9200/multi_documents/ferret/_mapping)' -d '{  
> "ferret":{  
> "properties":{  
> "docType":{ "type":"string" },  
> "ident\_ferret" : { "type" : "integer" }  
> }  
> }  
> }'  
> curl -XPUT '[http://localhost:9200/multi\_documents/wombat/\_mapping](http://localhost:9200/multi_documents/wombat/_mapping)' -d '{  
> "wombat":{  
> "properties" :{  
> "docType" : { "type" : "integer" },  
> "ident\_wombat" : { "type" : "integer" }  
> }  
> }  
> }'
> 
> load data:
> 
> curl -XPOST '[http://localhost:9200/multi\_documents/ferret/ferret-001](http://localhost:9200/multi_documents/ferret/ferret-001)' -d '{  
> "doc\_id":"ferret-001",  
> "docType" : "ferret",  
> "entityType" : "animal",  
> "ident\_ferret" : 200  
> }'  
> curl -XPOST '[http://localhost:9200/multi\_documents/wombat/wombat-001](http://localhost:9200/multi_documents/wombat/wombat-001)' -d '{  
> "doc\_id":"wombat-001",  
> "docType" : 10,  
> "entityType": "animal",  
> "ident\_wombat" : 100  
> }'
> 
> Query the index with field of same type in both document types ( SUCCESS ).  
> Both  
> "ferret" and "wombat" document are returned.
> 
> curl -XGET '[http://localhost:9200/multi\_documents/\_search](http://localhost:9200/multi_documents/_search)' -d '{  
> "size":100,  
> "query":{"field":{"entityType":"animal"}}  
> }'
> 
> Query across the document types ( by not defining them in URL ) asking for a  
> docType that is string ( SUCCESS ).  
> It returns the "ferret" document.
> 
> curl -XGET '[http://localhost:9200/multi\_documents/\_search](http://localhost:9200/multi_documents/_search)' -d '{  
> "size":100,  
> "query":{"field":{"docType":"ferret"}}  
> }'
> 
> Query across the document types ( by not defining them in URL ) asking for a  
> docType that is integer ( FAIL ). Should be getting "wombat" document  
> returned.  
> curl -XGET '[http://localhost:9200/multi\_documents/\_search](http://localhost:9200/multi_documents/_search)' -d '{  
> "size":100,  
> "query":{"field":{"docType":10}}  
> }'
> 
> To make the above query that fails to work, I have to explicitly define the  
> documentType in the field ( SUCCESS ).  
> It returns the "wombat" document.  
> curl -XGET '[http://localhost:9200/multi\_documents/\_search](http://localhost:9200/multi_documents/_search)' -d '{  
> "size":100,  
> "query":{"field":{"wombat.docType":10}}  
> }'
> 
> Try the query above but specify the document type in URL ( FAIL ). Should be  
> getting  
> "wombat" document returned.  
> curl -XGET '[http://localhost:9200/multi\_documents/wombat/\_search](http://localhost:9200/multi_documents/wombat/_search)' -d '{  
> "size":100,  
> "query":{"field":{"docType":10}}  
> }'
> 
> --

--

---

<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:05am UTC](https://discuss.elastic.co/t/query-behavior-for-an-index-with-multiple-document-types-and-mapping-per-doc-type-bug/9599/3 "2017-07-06T03:05:41Z")

</div>

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


