# Enforcing mapped types

**URL:** <https://discuss.elastic.co/t/enforcing-mapped-types/5044>\
**Category:** Elasticsearch\
**Created:** [August 3, 2011, 1:57pm UTC](https://discuss.elastic.co/t/enforcing-mapped-types/5044 "2011-08-03T13:57:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![riot\_irad](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@riot\_irad](https://discuss.elastic.co/u/riot_irad)\
**Post date:** [August 3, 2011, 1:57pm UTC](https://discuss.elastic.co/t/enforcing-mapped-types/5044/1 "2011-08-03T13:57:01Z")

</div>

Quick question: I've created a very simple mapping of a field to be an  
integer. A get of the \_mapping shows the following:  
$ curl -x '' -XGET '[http://localhost:9200/maptest/test/\_mapping](http://localhost:9200/maptest/test/_mapping)?  
pretty=true'  
{  
"test" : {  
"properties" : {  
"name" : {  
"type" : "string"  
},  
"int\_test" : {  
"store" : "yes",  
"type" : "integer"  
}  
}  
}  
}

However, it doesn't seem that the mapping is being enforced. If I  
create an object with a float or string value, it is accepted, and  
future GETs have the same float or string. i.e.:

$ curl -x '' -XPOST '[http://localhost:9200/maptest/test](http://localhost:9200/maptest/test)' -d  
'{ "name" : "whatever", "int\_test" : 5.22 }'  
{"ok":true,"\_index":"maptest","\_type":"test","\_id":"oO3ShWAlQp693b4b4mW3UQ","\_version":  
1}

$curl -x '' -XGET '[http://localhost:9200/maptest/test/](http://localhost:9200/maptest/test/)  
oO3ShWAlQp693b4b4mW3UQ'  
{"\_index":"maptest","\_type":"test","\_id":"oO3ShWAlQp693b4b4mW3UQ","\_version":  
1,"exists":true, "\_source" : { "name" : "whatever", "int\_test" :  
5.22 }}

$ curl -x '' -XGET '[http://localhost:9200/maptest/test/](http://localhost:9200/maptest/test/)  
oO3ShWAlQp693b4b4mW3UQ?fields=int\_test'  
{"\_index":"maptest","\_type":"test","\_id":"oO3ShWAlQp693b4b4mW3UQ","\_version":  
1,"exists":true,"fields":{"int\_test":5.22}}

What am I missing?

Thanks,

- Ruben

Also, sorry I've posted this a few times.... was having trouble having  
nabble recognize my subscription.

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 3, 2011, 2:36pm UTC](https://discuss.elastic.co/t/enforcing-mapped-types/5044/2 "2011-08-03T14:36:57Z")

</div>

Hi Ruben

> $curl -x '' -XGET '[http://localhost:9200/maptest/test/](http://localhost:9200/maptest/test/)  
> oO3ShWAlQp693b4b4mW3UQ'  
> {"\_index":"maptest","\_type":"test","\_id":"oO3ShWAlQp693b4b4mW3UQ","\_version":  
> 1,"exists":true, "\_source" : { "name" : "whatever", "int\_test" :  
> 5.22 }}

When you get a doc, you get back exactly the same JSON that you put in.  
That's not the same as the value that is being indexed.

clint

---

<div class="post-metadata">

**Author:** ![riot\_irad](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@riot\_irad](https://discuss.elastic.co/u/riot_irad)\
**Post date:** [August 3, 2011, 3:12pm UTC](https://discuss.elastic.co/t/enforcing-mapped-types/5044/3 "2011-08-03T15:12:42Z")

</div>

Right, I read in the documentation that the \_source is simply the  
original JSON, that's why we thought to try getting the individual  
fields (i.e. fields=int\_test), but even that returns the 5.22, so I'm  
guessing that just pulls it from there, too.

I tried searching, and that returned the 5.22 as well:

$ curl -x '' -XGET '[http://localhost:9200/maptest/test/\_search](http://localhost:9200/maptest/test/_search)?  
int\_test=5'  
{"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":  
5,"failed":0},"hits":{"total":1,"max\_score":1.0,"hits":  
[{"\_index":"maptest","\_type":"test","\_id":"oO3ShWAlQp693b4b4mW3UQ","\_score":  
1.0, "\_source" : { "name" : "whatever", "int\_test" : 5.22 }}]}}

$ curl -x '' -XGET '[http://localhost:9200/maptest/test/\_search](http://localhost:9200/maptest/test/_search)?  
int\_test=5.22'  
{"took":2,"timed\_out":false,"\_shards":{"total":5,"successful":  
5,"failed":0},"hits":{"total":1,"max\_score":1.0,"hits":  
[{"\_index":"maptest","\_type":"test","\_id":"oO3ShWAlQp693b4b4mW3UQ","\_score":  
1.0, "\_source" : { "name" : "whatever", "int\_test" : 5.22 }}]}}

I'm guessing that the second search returned the value because of the  
\_all field?

Is there a way to get the actual indexed value, or to have it reject  
values that don't match the field type? Otherwise, I feel there's a  
discrepancy between what I think a value is, and what it actually is.

- Ruben

On Aug 3, 10:36 am, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:

> Hi Ruben
> 
> > $curl -x '' -XGET '[http://localhost:9200/maptest/test/](http://localhost:9200/maptest/test/)  
> > oO3ShWAlQp693b4b4mW3UQ'  
> > {"\_index":"maptest","\_type":"test","\_id":"oO3ShWAlQp693b4b4mW3UQ","\_version ":  
> > 1,"exists":true, "\_source" : { "name" : "whatever", "int\_test" :  
> > 5.22 }}
> 
> When you get a doc, you get back exactly the same JSON that you put in.  
> That's not the same as the value that is being indexed.
> 
> clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 3, 2011, 5:15pm UTC](https://discuss.elastic.co/t/enforcing-mapped-types/5044/4 "2011-08-03T17:15:39Z")

</div>

On Wed, 2011-08-03 at 08:12 -0700, rfq wrote:

> Right, I read in the documentation that the \_source is simply the  
> original JSON, that's why we thought to try getting the individual  
> fields (i.e. fields=int\_test), but even that returns the 5.22, so I'm  
> guessing that just pulls it from there, too.
> 
> I tried searching, and that returned the 5.22 as well:

again, it just returns the \_source

> I'm guessing that the second search returned the value because of the  
> \_all field?

Correct

> Is there a way to get the actual indexed value, or to have it reject  
> values that don't match the field type? Otherwise, I feel there's a  
> discrepancy between what I think a value is, and what it actually is.

I don't think you can reject bad types.

To see what is actually happening, I've gisted a short example which  
uses term facets to retrieve the actual values that are stored in a  
field of type integer, float, and \_all (which by default is a string  
field).

> <https://gist.github.com/clintongormley/e598ccfd3fa67830b689>

clint

---

<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 3, 2011, 5:43pm UTC](https://discuss.elastic.co/t/enforcing-mapped-types/5044/5 "2011-08-03T17:43:03Z")

</div>

It won't reject a float value for an int field, it will simply convert it to  
an int value.

On Wed, Aug 3, 2011 at 8:15 PM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> On Wed, 2011-08-03 at 08:12 -0700, rfq wrote:
> 
> > Right, I read in the documentation that the \_source is simply the  
> > original JSON, that's why we thought to try getting the individual  
> > fields (i.e. fields=int\_test), but even that returns the 5.22, so I'm  
> > guessing that just pulls it from there, too.
> > 
> > I tried searching, and that returned the 5.22 as well:
> 
> again, it just returns the \_source
> 
> > I'm guessing that the second search returned the value because of the  
> > \_all field?
> 
> Correct
> 
> > Is there a way to get the actual indexed value, or to have it reject  
> > values that don't match the field type? Otherwise, I feel there's a  
> > discrepancy between what I think a value is, and what it actually is.
> 
> I don't think you can reject bad types.
> 
> To see what is actually happening, I've gisted a short example which  
> uses term facets to retrieve the actual values that are stored in a  
> field of type integer, float, and \_all (which by default is a string  
> field).
> 
> [gist:e598ccfd3fa67830b689 · GitHub](https://gist.github.com/e598ccfd3fa67830b689)
> 
> clint

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 3, 2011, 5:57pm UTC](https://discuss.elastic.co/t/enforcing-mapped-types/5044/6 "2011-08-03T17:57:05Z")

</div>

> To see what is actually happening, I've gisted a short example which  
> uses term facets to retrieve the actual values that are stored in a  
> field of type integer, float, and \_all (which by default is a string  
> field).

Apologies - i had some errors in my previous gist.

Corrected: [gist:e598ccfd3fa67830b689 · GitHub](https://gist.github.com/e598ccfd3fa67830b689)

---

<div class="post-metadata">

**Author:** ![riot\_irad](https://avatars.discourse-cdn.com/v4/letter/r/b2d939/32.png) [@riot\_irad](https://discuss.elastic.co/u/riot_irad)\
**Post date:** [August 3, 2011, 7:01pm UTC](https://discuss.elastic.co/t/enforcing-mapped-types/5044/7 "2011-08-03T19:01:58Z")

</div>

Cool, that makes sense, thanks.

On Aug 3, 1:57 pm, Clinton Gormley [cl...@traveljury.com](mailto:cl...@traveljury.com) wrote:

> > To see what is actually happening, I've gisted a short example which  
> > uses term facets to retrieve the actual values that are stored in a  
> > field of type integer, float, and \_all (which by default is a string  
> > field).
> 
> Apologies - i had some errors in my previous gist.
> 
> Corrected:[gist:e598ccfd3fa67830b689 · GitHub](https://gist.github.com/e598ccfd3fa67830b689)

---

<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:58am UTC](https://discuss.elastic.co/t/enforcing-mapped-types/5044/8 "2017-07-06T03:58:19Z")

</div>


