# Problems with Query\_String and different field types

**URL:** <https://discuss.elastic.co/t/problems-with-query-string-and-different-field-types/4504>\
**Category:** Elasticsearch\
**Created:** [May 31, 2011, 11:49am UTC](https://discuss.elastic.co/t/problems-with-query-string-and-different-field-types/4504 "2011-05-31T11:49:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maho](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@maho](https://discuss.elastic.co/u/maho)\
**Post date:** [May 31, 2011, 11:49am UTC](https://discuss.elastic.co/t/problems-with-query-string-and-different-field-types/4504/1 "2011-05-31T11:49:06Z")

</div>

Hi,

I have an index with two fields:

- name: description, type: string
- name: price, type: double

If I send following query, I get an NumberFormatException[For input  
string: "car"]

curl -XGET '[http://localhost:9200/sample/products/\_search?pretty](http://localhost:9200/sample/products/_search?pretty)' -d  
'{  
"query" : {  
"query\_string" : {  
"fields": ["description", "price"],  
"query": "car"  
}  
}  
}'

Of course, "car" cant be parsed to double, but can this be ignored?

Thanks.

---

<div class="post-metadata">

**Author:** ![maho](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@maho](https://discuss.elastic.co/u/maho)\
**Post date:** [June 1, 2011, 7:01am UTC](https://discuss.elastic.co/t/problems-with-query-string-and-different-field-types/4504/2 "2011-06-01T07:01:09Z")

</div>

Has no one an idea?

Or should i report an issue?

On 31 Mai, 13:49, maho [mathias.hod...@gmail.com](mailto:mathias.hod...@gmail.com) wrote:

> Hi,
> 
> I have an index with two fields:
> 
> - name: description, type: string
> - name: price, type: double
> 
> If I send following query, I get an NumberFormatException[For input  
> string: "car"]
> 
> curl -XGET '[http://localhost:9200/sample/products/\_search?pretty'-d](http://localhost:9200/sample/products/_search?pretty'-d)  
> '{  
> "query" : {  
> "query\_string" : {  
> "fields": ["description", "price"],  
> "query": "car"  
> }  
> }
> 
> }'
> 
> Of course, "car" cant be parsed to double, but can this be ignored?
> 
> Thanks.

---

<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:** [June 1, 2011, 9:19am UTC](https://discuss.elastic.co/t/problems-with-query-string-and-different-field-types/4504/3 "2011-06-01T09:19:13Z")

</div>

> > curl -XGET '[http://localhost:9200/sample/products/\_search?pretty'-d](http://localhost:9200/sample/products/_search?pretty'-d)  
> > '{  
> > "query" : {  
> > "query\_string" : {  
> > "fields": ["description", "price"],  
> > "query": "car"  
> > }

Why are you searching for 'car' against the field 'price'?

If you actually want to search for 'car' against the field 'description'  
then use { "default\_field": "description", "query": "car" }

Then if you want just the 'description' and 'price' fields to be  
returned in the search results, you can use the "fields" clause above,  
but at the same level as "query", not inside the query clause

clint

---

<div class="post-metadata">

**Author:** ![maho](https://avatars.discourse-cdn.com/v4/letter/m/4da419/32.png) [@maho](https://discuss.elastic.co/u/maho)\
**Post date:** [June 1, 2011, 11:13am UTC](https://discuss.elastic.co/t/problems-with-query-string-and-different-field-types/4504/4 "2011-06-01T11:13:41Z")

</div>

Because I don't know what a user enters in the search field.

Maybe "car 2500" or "1300" or "car"

So what should I do if the user enters "car 2500"?  
Of course I could parse the text and then building an appropriate  
query. But that is too extensive, especially if you have more than two  
fields.

In my opinion the would be best if ES ignoring unparsable text for the  
particular field and not throwing an exception.

On 1 Jun., 11:19, Clinton Gormley [clin...@iannounce.co.uk](mailto:clin...@iannounce.co.uk) wrote:

> > > curl -XGET '[http://localhost:9200/sample/products/\_search?pretty'-d](http://localhost:9200/sample/products/_search?pretty'-d)  
> > > '{  
> > > "query" : {  
> > > "query\_string" : {  
> > > "fields": ["description", "price"],  
> > > "query": "car"  
> > > }
> 
> Why are you searching for 'car' against the field 'price'?
> 
> If you actually want to search for 'car' against the field 'description'  
> then use { "default\_field": "description", "query": "car" }
> 
> Then if you want just the 'description' and 'price' fields to be  
> returned in the search results, you can use the "fields" clause above,  
> but at the same level as "query", not inside the query clause
> 
> clint

---

<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, 4:05am UTC](https://discuss.elastic.co/t/problems-with-query-string-and-different-field-types/4504/5 "2017-07-06T04:05:03Z")

</div>


