Mapper-size plugin not working

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"?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' -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" :
}
}

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

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

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.

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