# Question about specific field searches

**URL:** <https://discuss.elastic.co/t/question-about-specific-field-searches/7210>\
**Category:** Elasticsearch\
**Created:** [April 3, 2012, 3:02pm UTC](https://discuss.elastic.co/t/question-about-specific-field-searches/7210 "2012-04-03T15:02:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tom\_Tayon\_2](https://avatars.discourse-cdn.com/v4/letter/t/f07891/32.png) [@Tom\_Tayon\_2](https://discuss.elastic.co/u/Tom_Tayon_2)\
**Post date:** [April 3, 2012, 3:02pm UTC](https://discuss.elastic.co/t/question-about-specific-field-searches/7210/1 "2012-04-03T15:02:00Z")

</div>

Hello,

I am trying to do a search using the Java API on a specific field  
using the QueryStringQueryBuilder.field.

If I have 2 fields, one of type Integer, and one of type String, and  
do a standard query across all fields for "bob", the search works as  
expected.

If I tell the system to narrow the search to only the Integer field,  
then search for "123", everything works as expected.

However, the search for "bob" results in a NumberFormatException[For  
input string: "bob"]

It is apparently trying to convert "bob" to a number to do the search.  
I cannot easily restrict what the user types in the search to know if  
everything will convert. I would rather not have to parse the user  
input looking for anything that will not match any field type that may  
be selected. (We have dozens of different fields of different types)

Is this a known issue, or am I possibly doing something wrong? Why  
does this work when I search across all fields?

Thanks for any help in the matter,

Tom

---

<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:** [April 4, 2012, 3:04pm UTC](https://discuss.elastic.co/t/question-about-specific-field-searches/7210/2 "2012-04-04T15:04:56Z")

</div>

Yea, the parser will try and use the provided value and convert it to  
numeric if you query against it. You can do a simple check on the query  
string, and if it is numeric, then query the integer field.

On Tue, Apr 3, 2012 at 6:02 PM, Tom Tayon [tomtayon@gmail.com](mailto:tomtayon@gmail.com) wrote:

> Hello,
> 
> I am trying to do a search using the Java API on a specific field  
> using the QueryStringQueryBuilder.field.
> 
> If I have 2 fields, one of type Integer, and one of type String, and  
> do a standard query across all fields for "bob", the search works as  
> expected.
> 
> If I tell the system to narrow the search to only the Integer field,  
> then search for "123", everything works as expected.
> 
> However, the search for "bob" results in a NumberFormatException[For  
> input string: "bob"]
> 
> It is apparently trying to convert "bob" to a number to do the search.  
> I cannot easily restrict what the user types in the search to know if  
> everything will convert. I would rather not have to parse the user  
> input looking for anything that will not match any field type that may  
> be selected. (We have dozens of different fields of different types)
> 
> Is this a known issue, or am I possibly doing something wrong? Why  
> does this work when I search across all fields?
> 
> Thanks for any help in the matter,
> 
> Tom

---

<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:33am UTC](https://discuss.elastic.co/t/question-about-specific-field-searches/7210/3 "2017-07-06T03:33:39Z")

</div>


