# Number of characters in field

**URL:** <https://discuss.elastic.co/t/number-of-characters-in-field/17667>\
**Category:** Elasticsearch\
**Created:** [May 22, 2014, 7:45am UTC](https://discuss.elastic.co/t/number-of-characters-in-field/17667 "2014-05-22T07:45:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Nielsen](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@David\_Nielsen](https://discuss.elastic.co/u/David_Nielsen)\
**Post date:** [May 22, 2014, 7:45am UTC](https://discuss.elastic.co/t/number-of-characters-in-field/17667/1 "2014-05-22T07:45:41Z")

</div>

Hi.  
I am trying to find a way to express a character count filter in a  
querystring, for instance: I need to find all documents with field  
"subject" that holds less than 20 chars.  
How would i do that in a querystring ?

/David

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4163e674-b9ec-4be1-b142-c5636521f573%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4163e674-b9ec-4be1-b142-c5636521f573%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![dantuff](https://avatars.discourse-cdn.com/v4/letter/d/e79b87/32.png) [@dantuff](https://discuss.elastic.co/u/dantuff)\
**Post date:** [May 22, 2014, 12:30pm UTC](https://discuss.elastic.co/t/number-of-characters-in-field/17667/2 "2014-05-22T12:30:30Z")

</div>

You could use a script filter:

"filtered" : {  
"query" : {  
...  
},  
"filter" : {  
"script" : {  
"script" : "doc['subject'].value.length() \< 20"  
}  
}  
}

Dan

On Thursday, May 22, 2014 8:45:41 AM UTC+1, David Nielsen wrote:

> Hi.  
> I am trying to find a way to express a character count filter in a  
> querystring, for instance: I need to find all documents with field  
> "subject" that holds less than 20 chars.  
> How would i do that in a querystring ?
> 
> /David

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/9d7cff9d-1449-4635-b780-89ce6102ec77%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/9d7cff9d-1449-4635-b780-89ce6102ec77%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![David\_Nielsen](https://avatars.discourse-cdn.com/v4/letter/d/2bfe46/32.png) [@David\_Nielsen](https://discuss.elastic.co/u/David_Nielsen)\
**Post date:** [May 22, 2014, 12:47pm UTC](https://discuss.elastic.co/t/number-of-characters-in-field/17667/3 "2014-05-22T12:47:28Z")

</div>

Well yes i know that one, is this really the only/best way to do it?.  
My application is forwarding an input field directly to a querystring, the  
user need to be able to query something like this:

tags:h1 AND subject:lenght\>20

On Thursday, May 22, 2014 2:30:30 PM UTC+2, Dan Tuffery wrote:

> You could use a script filter:
> 
> "filtered" : {  
> "query" : {  
> ...  
> },  
> "filter" : {  
> "script" : {  
> "script" : "doc['subject'].value.length() \< 20"  
> }  
> }  
> }
> 
> Dan
> 
> On Thursday, May 22, 2014 8:45:41 AM UTC+1, David Nielsen wrote:
> 
> > Hi.  
> > I am trying to find a way to express a character count filter in a  
> > querystring, for instance: I need to find all documents with field  
> > "subject" that holds less than 20 chars.  
> > How would i do that in a querystring ?
> > 
> > /David

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/2d4f588a-4655-4286-9e12-4d4b4d0015e6%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2d4f588a-4655-4286-9e12-4d4b4d0015e6%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:27am UTC](https://discuss.elastic.co/t/number-of-characters-in-field/17667/4 "2017-07-06T01:27:39Z")

</div>


