# Type or field

**URL:** <https://discuss.elastic.co/t/type-or-field/8064>\
**Category:** Elasticsearch\
**Created:** [June 12, 2012, 5:16pm UTC](https://discuss.elastic.co/t/type-or-field/8064 "2012-06-12T17:16:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![arta](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@arta](https://discuss.elastic.co/u/arta)\
**Post date:** [June 12, 2012, 5:16pm UTC](https://discuss.elastic.co/t/type-or-field/8064/1 "2012-06-12T17:16:46Z")

</div>

Hi,  
I have only one document type (only one mapping).  
The documents are grouped, for example, by zip code.  
And our searches are always bound within a group, for example only for 94040.  
We do not search on multiple groups.  
In this situation, which design is better?:

1. have the zip code as a type, so that we can search only for that zip code by issueing search query  
"[http://localhost:9200/](http://localhost:9200/)/94040/\_search" ...
2. have the zip code as a field, then filter by the field  
"[http://localhost:9200/](http://localhost:9200/)//\_search" -d '{  
"query":{"filtered":{"query":{..},"filter":{"term":{"zip":94040}}}}}'

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [June 12, 2012, 7:51pm UTC](https://discuss.elastic.co/t/type-or-field/8064/2 "2012-06-12T19:51:14Z")

</div>

I do not think there is a difference in performance. Mappings are  
defined by type, so it would be easier to maintain a mapping against a  
fixed type and not need a dynamic mapping across all types in an  
index, IMHO.

On Tue, Jun 12, 2012 at 10:16 AM, arta [artasano@sbcglobal.net](mailto:artasano@sbcglobal.net) wrote:

> Hi,  
> I have only one document type (only one mapping).  
> The documents are grouped, for example, by zip code.  
> And our searches are always bound within a group, for example only for  
> 94040.  
> We do not search on multiple groups.  
> In this situation, which design is better?:
> 
> 1. have the zip code as a type, so that we can search only for that zip code  
> by issueing search query  
> "[http://localhost:9200/](http://localhost:9200/)/94040/\_search" ...
> 2. have the zip code as a field, then filter by the field  
> "[http://localhost:9200/](http://localhost:9200/)//\_search" -d '{  
> "query":{"filtered":{"query":{..},"filter":{"term":{"zip":94040}}}}}'
> 
> Thank you for your help.
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/type-or-field-tp4019143.html](http://elasticsearch-users.115913.n3.nabble.com/type-or-field-tp4019143.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![arta](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@arta](https://discuss.elastic.co/u/arta)\
**Post date:** [June 13, 2012, 4:50pm UTC](https://discuss.elastic.co/t/type-or-field/8064/3 "2012-06-13T16:50:38Z")

</div>

Thank you Ivan,  
Good to know there isn't much difference.

Here'are my concerns:

1. have the zip code as a type, so that we can search only for that zip code by specifying 'type'  
Pros:

- easy to construct query, as no explicit filter clause is necessary
- no need to have 'zip\_code' field. so presumably saving disk space?
- type handling is a built-in feature of ES, so presumably faster processing than query filter?  
Cons:
- I guess, _default_ mapping is copied for each type when a type is added, so more memory consumption?

1. have the zip code as a field, then apply a filter by the field  
Pros and cons opposite to 1)

In general, I'd like to know the difference in terms of, disk-usage, memory-consumption and search-speed.  
Thanks, again, for your help.

---

<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:** [June 14, 2012, 9:40pm UTC](https://discuss.elastic.co/t/type-or-field/8064/4 "2012-06-14T21:40:57Z")

</div>

There isn't a difference in terms of perf or disk store, a type is actually  
stored as another field in a doc. You will create multiple mappings in this  
case for each zip, which is a waste in terms of storing the cluster state.  
So, use a field and filter by it.

On Wed, Jun 13, 2012 at 6:50 PM, arta [artasano@sbcglobal.net](mailto:artasano@sbcglobal.net) wrote:

> Thank you Ivan,  
> Good to know there isn't much difference.
> 
> Here'are my concerns:
> 
> 1. have the zip code as a type, so that we can search only for that zip  
> code  
> by specifying 'type'  
> Pros:
> 
> - easy to construct query, as no explicit filter clause is necessary
> - no need to have 'zip\_code' field. so presumably saving disk space?
> - type handling is a built-in feature of ES, so presumably faster  
> processing than query filter?  
> Cons:
> - I guess, _default_ mapping is copied for each type when a type is added,  
> so more memory consumption?
> 
> 1. have the zip code as a field, then apply a filter by the field  
> Pros and cons opposite to 1)
> 
> In general, I'd like to know the difference in terms of, disk-usage,  
> memory-consumption and search-speed.  
> Thanks, again, for your help.
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/type-or-field-tp4019143p4019220.html](http://elasticsearch-users.115913.n3.nabble.com/type-or-field-tp4019143p4019220.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![arta](https://avatars.discourse-cdn.com/v4/letter/a/aca169/32.png) [@arta](https://discuss.elastic.co/u/arta)\
**Post date:** [June 19, 2012, 3:35am UTC](https://discuss.elastic.co/t/type-or-field/8064/5 "2012-06-19T03:35:25Z")

</div>

Thank you, kimchy.

---

<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:23am UTC](https://discuss.elastic.co/t/type-or-field/8064/6 "2017-07-06T03:23:31Z")

</div>

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


