# Mapper-size plugin not working

**URL:** <https://discuss.elastic.co/t/mapper-size-plugin-not-working/98123>\
**Category:** Elasticsearch\
**Created:** [August 23, 2017, 7:15pm UTC](https://discuss.elastic.co/t/mapper-size-plugin-not-working/98123 "2017-08-23T19:15:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aliyesami](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@aliyesami](https://discuss.elastic.co/u/aliyesami)\
**Post date:** [August 23, 2017, 7:15pm UTC](https://discuss.elastic.co/t/mapper-size-plugin-not-working/98123/1 "2017-08-23T19:15:40Z")

</div>

I have modified the mapping to add "\_size" but I still can't get documents with certain field sizes .  
basically I want to get all the documents where the "name" field is less than 4 chars

> [elasticsearch@hadoop1 ~]$ curl -XGET "[http://hadoop5:9200/sports/\_mapping](http://hadoop5:9200/sports/_mapping)"?pretty  
> {  
> "sports" : {  
> "mappings" : {  
> "athlete" : {  
> "\_size" : {  
> "enabled" : true  
> },  
> "properties" : {  
> "birthdate" : {  
> "type" : "date",  
> "format" : "dateOptionalTime"  
> },  
> "location" : {  
> "type" : "geo\_point"  
> },  
> "name" : {  
> "type" : "text",  
> "fielddata" : true  
> },  
> "rating" : {  
> "type" : "integer"  
> },  
> "sport" : {  
> "type" : "text"  
> }}}}}}

I have bunch of documents with name field populated as follows

> "name" : "Ray"  
> "name" : "Mick"

the below query fails to find any documents where name is less than 5 characters.

> curl -XGET '[http://hadoop5:9200/sports/\_search?pretty](http://hadoop5:9200/sports/_search?pretty)' -d '  
> {  
> "query": {  
> "range": {  
> "\_size": {  
> "lt": 5  
> }  
> }  
> }  
> }'
> 
> {  
> "took" : 1,  
> "timed\_out" : false,  
> "\_shards" : {  
> "total" : 5,  
> "successful" : 5,  
> "failed" : 0  
> },  
> "hits" : {  
> "total" : 0,  
> "max\_score" : null,  
> "hits" :   
> }  
> }

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [August 23, 2017, 9:07pm UTC](https://discuss.elastic.co/t/mapper-size-plugin-not-working/98123/2 "2017-08-23T21:07:07Z")

</div>

The `_size` is the size of the entire json document, including field names and the json structure.

---

<div class="post-metadata">

**Author:** ![aliyesami](https://avatars.discourse-cdn.com/v4/letter/a/ecb155/32.png) [@aliyesami](https://discuss.elastic.co/u/aliyesami)\
**Post date:** [August 24, 2017, 9:48pm UTC](https://discuss.elastic.co/t/mapper-size-plugin-not-working/98123/3 "2017-08-24T21:48:30Z")

</div>

so how can I get all the documents where the “name” field is less than 4 chars ?

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [August 25, 2017, 5:43am UTC](https://discuss.elastic.co/t/mapper-size-plugin-not-working/98123/4 "2017-08-25T05:43:30Z")

</div>

You probably want to use a script, and look at the size of the `name.keyword` field (which will contain the original raw string). Note this is a slow operation though (like a scan on a db). It would be better if when ingesting your documents you added a field like `name_size` which contained the length of the field. Then you could more efficiently run a numeric range query on that field.

---

<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:** [September 22, 2017, 5:43am UTC](https://discuss.elastic.co/t/mapper-size-plugin-not-working/98123/5 "2017-09-22T05:43:32Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
