# Searching across types

**URL:** <https://discuss.elastic.co/t/searching-across-types/3463>\
**Category:** Elasticsearch\
**Created:** [October 21, 2010, 12:55pm UTC](https://discuss.elastic.co/t/searching-across-types/3463 "2010-10-21T12:55:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [October 21, 2010, 12:55pm UTC](https://discuss.elastic.co/t/searching-across-types/3463/1 "2010-10-21T12:55:03Z")

</div>

When performing a search across multiple types, is is possible to indicate  
the fields that should be searched on a per-type basis?

---

<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:** [October 21, 2010, 9:44pm UTC](https://discuss.elastic.co/t/searching-across-types/3463/2 "2010-10-21T21:44:32Z")

</div>

Let me explain a bit how types work in elasticsearch. At the end of the day,  
Lucene index has Documents and has no notion of types. Types are something  
added (as best as possible) by elasticsearch. A lucene document is a flat  
structure key value pair (so objects in json are also translated to this),  
and a type ends up as another field within the document (called \_type).

Then you build a query and in the field (any query that acces a field to  
execute on), you can specify type1.field1, and in this case, it will be  
automatically detected, and the query will be wrapped to only be executed  
match on docs with \_type:type1 (in an efficient manner), on field1.

This does mean that across types, having the same field name with different  
mappings types (for example, type1 has field1 of type numeric, and type2  
also has field1 but of type string) should not be done (working on  
automatically detecting that...).

So, the type prefix when you define the field name should allow to only  
search on a field against that specific type. (At the end of the day, it is  
wrapped in a filtered query with a \_type:type1 term filter).

-shay.banon

On Thu, Oct 21, 2010 at 2:55 PM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:

> When performing a search across multiple types, is is possible to indicate  
> the fields that should be searched on a per-type basis?

---

<div class="post-metadata">

**Author:** ![James\_Cook](https://avatars.discourse-cdn.com/v4/letter/j/898d66/32.png) [@James\_Cook](https://discuss.elastic.co/u/James_Cook)\
**Post date:** [October 22, 2010, 4:32pm UTC](https://discuss.elastic.co/t/searching-across-types/3463/3 "2010-10-22T16:32:45Z")

</div>

That's such good information, and makes it much clearer for me. Thank you.

On Thu, Oct 21, 2010 at 5:44 PM, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com)wrote:

> Let me explain a bit how types work in elasticsearch. At the end of the  
> day, Lucene index has Documents and has no notion of types. Types are  
> something added (as best as possible) by elasticsearch. A lucene document is  
> a flat structure key value pair (so objects in json are also translated to  
> this), and a type ends up as another field within the document (called  
> \_type).
> 
> Then you build a query and in the field (any query that acces a field to  
> execute on), you can specify type1.field1, and in this case, it will be  
> automatically detected, and the query will be wrapped to only be executed  
> match on docs with \_type:type1 (in an efficient manner), on field1.
> 
> This does mean that across types, having the same field name with different  
> mappings types (for example, type1 has field1 of type numeric, and type2  
> also has field1 but of type string) should not be done (working on  
> automatically detecting that...).
> 
> So, the type prefix when you define the field name should allow to only  
> search on a field against that specific type. (At the end of the day, it is  
> wrapped in a filtered query with a \_type:type1 term filter).
> 
> -shay.banon
> 
> On Thu, Oct 21, 2010 at 2:55 PM, James Cook [jcook@tracermedia.com](mailto:jcook@tracermedia.com) wrote:
> 
> > When performing a search across multiple types, is is possible to indicate  
> > the fields that should be searched on a per-type basis?

---

<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, 4:17am UTC](https://discuss.elastic.co/t/searching-across-types/3463/4 "2017-07-06T04:17:40Z")

</div>


