# Date parsing exception

**URL:** <https://discuss.elastic.co/t/date-parsing-exception/7716>\
**Category:** Elasticsearch\
**Created:** [May 16, 2012, 9:12am UTC](https://discuss.elastic.co/t/date-parsing-exception/7716 "2012-05-16T09:12:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkleen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mkleen/32/1694_2.png) [@mkleen](https://discuss.elastic.co/u/mkleen)\
**Post date:** [May 16, 2012, 9:12am UTC](https://discuss.elastic.co/t/date-parsing-exception/7716/1 "2012-05-16T09:12:39Z")

</div>

Hello,

When I create an object with a date using the default dynamic mapping  
and query this field afterwards with a non-date value, I get a  
SearchParseException. Would it be possible to change the behavior  
that the query will be simply ignored or my term will be set to a  
default value without changing the parseStringValue in the  
DateFieldMapper.java ? Could I possibly include my own DateFieldMapper  
as a plugin or is there even an easier way to archieve this ?

Many thanks,

Michael

curl -XPUT [http://localhost:9200/test/foo/1](http://localhost:9200/test/foo/1) -d '{  
"start" : "2012-11-15T14:12:12"  
}'

curl -XGET [http://localhost:9200/test/foo/\_search](http://localhost:9200/test/foo/_search) -d '{  
"query" : {  
"term" : { "start": "bar" }  
}  
}'

{"error":"SearchPhaseExecutionException[Failed to execute phase  
[query\_fetch], total failure; shardFailures {[vGv3rzeqQN6wc-boRT\_QKg]  
[test][0]: SearchParseException[[test][0]: from[-1],size[-1]: Parse  
Failure [Failed to parse source [{\n "query" : {\n "term  
" : { "start": "bar" }\n }\n}]]]; nested:  
MapperParsingException[failed to parse date field, tried both date  
format [dateOptionalTime], and timestamp number]; nested:  
IllegalArgumentException[Invalid format: "bar"]; }]","status":500}

---

<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:** [May 16, 2012, 10:16pm UTC](https://discuss.elastic.co/t/date-parsing-exception/7716/2 "2012-05-16T22:16:33Z")

</div>

In upcoming 0.19.4, there is support for lenient query\_string query (but  
not term query, since it is assumed that you know what you do if you build  
a term query, I guess):  
[Query String: Add `lenient` flag to support \*value\* parse failures · Issue #1932 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1932).

On Wed, May 16, 2012 at 12:12 PM, mkleen [mkleen@gmail.com](mailto:mkleen@gmail.com) wrote:

> Hello,
> 
> When I create an object with a date using the default dynamic mapping  
> and query this field afterwards with a non-date value, I get a  
> SearchParseException. Would it be possible to change the behavior  
> that the query will be simply ignored or my term will be set to a  
> default value without changing the parseStringValue in the  
> DateFieldMapper.java ? Could I possibly include my own DateFieldMapper  
> as a plugin or is there even an easier way to archieve this ?
> 
> Many thanks,
> 
> Michael
> 
> curl -XPUT [http://localhost:9200/test/foo/1](http://localhost:9200/test/foo/1) -d '{  
> "start" : "2012-11-15T14:12:12"  
> }'
> 
> curl -XGET [http://localhost:9200/test/foo/\_search](http://localhost:9200/test/foo/_search) -d '{  
> "query" : {  
> "term" : { "start": "bar" }  
> }  
> }'
> 
> {"error":"SearchPhaseExecutionException[Failed to execute phase  
> [query\_fetch], total failure; shardFailures {[vGv3rzeqQN6wc-boRT\_QKg]  
> [test][0]: SearchParseException[[test][0]: from[-1],size[-1]: Parse  
> Failure [Failed to parse source [{\n "query" : {\n "term  
> " : { "start": "bar" }\n }\n}]]]; nested:  
> MapperParsingException[failed to parse date field, tried both date  
> format [dateOptionalTime], and timestamp number]; nested:  
> IllegalArgumentException[Invalid format: "bar"]; }]","status":500}

---

<div class="post-metadata">

**Author:** ![Michael\_Kleen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_kleen/32/2496_2.png) [@Michael\_Kleen](https://discuss.elastic.co/u/Michael_Kleen)\
**Post date:** [May 18, 2012, 10:20am UTC](https://discuss.elastic.co/t/date-parsing-exception/7716/3 "2012-05-18T10:20:02Z")

</div>

Very nice, this is exactly what I was looking for. Would it make sense to  
get a "lenient" parameter also for other queries such as text or term ? I  
would love to have this feature without having been forced to use a query  
parser. Btw: Do I understand this right that the wildcard support for paths  
for the fields such as "fields" : "city.\*" is also only supported to have  
for the query\_string query and not for other queries ?

Thanks for your time,

Michael

On Thursday, May 17, 2012 12:16:33 AM UTC+2, kimchy wrote:

> In upcoming 0.19.4, there is support for lenient query\_string query (but  
> not term query, since it is assumed that you know what you do if you build  
> a term query, I guess):  
> [Query String: Add `lenient` flag to support \*value\* parse failures · Issue #1932 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/1932).
> 
> On Wed, May 16, 2012 at 12:12 PM, mkleen wrote:
> 
> > Hello,
> > 
> > When I create an object with a date using the default dynamic mapping  
> > and query this field afterwards with a non-date value, I get a  
> > SearchParseException. Would it be possible to change the behavior  
> > that the query will be simply ignored or my term will be set to a  
> > default value without changing the parseStringValue in the  
> > DateFieldMapper.java ? Could I possibly include my own DateFieldMapper  
> > as a plugin or is there even an easier way to archieve this ?
> > 
> > Many thanks,
> > 
> > Michael
> > 
> > curl -XPUT [http://localhost:9200/test/foo/1](http://localhost:9200/test/foo/1) -d '{  
> > "start" : "2012-11-15T14:12:12"  
> > }'
> > 
> > curl -XGET [http://localhost:9200/test/foo/\_search](http://localhost:9200/test/foo/_search) -d '{  
> > "query" : {  
> > "term" : { "start": "bar" }  
> > }  
> > }'
> > 
> > {"error":"SearchPhaseExecutionException[Failed to execute phase  
> > [query\_fetch], total failure; shardFailures {[vGv3rzeqQN6wc-boRT\_QKg]  
> > [test][0]: SearchParseException[[test][0]: from[-1],size[-1]: Parse  
> > Failure [Failed to parse source [{\n "query" : {\n "term  
> > " : { "start": "bar" }\n }\n}]]]; nested:  
> > MapperParsingException[failed to parse date field, tried both date  
> > format [dateOptionalTime], and timestamp number]; nested:  
> > IllegalArgumentException[Invalid format: "bar"]; }]","status":500}

---

<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:** [May 20, 2012, 8:22pm UTC](https://discuss.elastic.co/t/date-parsing-exception/7716/4 "2012-05-20T20:22:41Z")

</div>

Yes, the wildcard aspect is only supported for query\_string, as well as  
lenient. Its kindda tricky to support it in other elements, since it means  
compound queries (ones that inner parse the term query, like bool query)  
will need to know how to handle "null" queries.

On Fri, May 18, 2012 at 12:20 PM, Michael Kleen \<michael.kleen@numberfour.eu

> wrote:

> Very nice, this is exactly what I was looking for. Would it make sense to  
> get a "lenient" parameter also for other queries such as text or term ? I  
> would love to have this feature without having been forced to use a query  
> parser. Btw: Do I understand this right that the wildcard support for paths  
> for the fields such as "fields" : "city.\*" is also only supported to have  
> for the query\_string query and not for other queries ?
> 
> Thanks for your time,
> 
> Michael
> 
> On Thursday, May 17, 2012 12:16:33 AM UTC+2, kimchy wrote:
> 
> > In upcoming 0.19.4, there is support for lenient query\_string query (but  
> > not term query, since it is assumed that you know what you do if you build  
> > a term query, I guess): [https://github.com/\*\*elasticsearch/elasticsearch/](https://github.com/**elasticsearch/elasticsearch/)  
> > \*\*issues/1932[https://github.com/elasticsearch/elasticsearch/issues/1932](https://github.com/elasticsearch/elasticsearch/issues/1932)  
> > .
> > 
> > On Wed, May 16, 2012 at 12:12 PM, mkleen wrote:
> > 
> > Hello,
> > 
> > > When I create an object with a date using the default dynamic mapping  
> > > and query this field afterwards with a non-date value, I get a  
> > > SearchParseException. Would it be possible to change the behavior  
> > > that the query will be simply ignored or my term will be set to a  
> > > default value without changing the parseStringValue in the  
> > > DateFieldMapper.java ? Could I possibly include my own DateFieldMapper  
> > > as a plugin or is there even an easier way to archieve this ?
> > > 
> > > Many thanks,
> > > 
> > > Michael
> > > 
> > > curl -XPUT [http://localhost:9200/test/\*\*foo/1](http://localhost:9200/test/**foo/1)[http://localhost:9200/test/foo/1](http://localhost:9200/test/foo/1)-d '{  
> > > "start" : "2012-11-15T14:12:12"  
> > > }'
> > > 
> > > curl -XGET [http://localhost:9200/test/\*\*foo/\_search](http://localhost:9200/test/**foo/_search)[http://localhost:9200/test/foo/\_search](http://localhost:9200/test/foo/_search)-d '{  
> > > "query" : {  
> > > "term" : { "start": "bar" }  
> > > }  
> > > }'
> > > 
> > > {"error":"\*\*SearchPhaseExecutionException[**Failed to execute phase  
> > > [query\_fetch], total failure; shardFailures {[vGv3rzeqQN6wc-boRT\_QKg]  
> > > [test][0]: SearchParseException[[test][0]**: from[-1],size[-1]: Parse  
> > > Failure [Failed to parse source [{\n "query" : {\n "term  
> > > " : { "start": "bar" }\n }\n}]]]; nested:  
> > > MapperParsingException[failed to parse date field, tried both date  
> > > format [dateOptionalTime], and timestamp number]; nested:  
> > > IllegalArgumentException[\*\*Invalid format: "bar"]; }]","status":500}

---

<div class="post-metadata">

**Author:** ![mkleen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mkleen/32/1694_2.png) [@mkleen](https://discuss.elastic.co/u/mkleen)\
**Post date:** [May 21, 2012, 8:03am UTC](https://discuss.elastic.co/t/date-parsing-exception/7716/5 "2012-05-21T08:03:29Z")

</div>

On Sunday, May 20, 2012 10:22:41 PM UTC+2, kimchy wrote:

> Yes, the wildcard aspect is only supported for query\_string, as well as  
> lenient. Its kindda tricky to support it in other elements, since it means  
> compound queries (ones that inner parse the term query, like bool query)  
> will need to know how to handle "null" queries.

Oh, does this mean a query\_string query should not be used in a compound  
query ?

---

<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:** [May 21, 2012, 8:35am UTC](https://discuss.elastic.co/t/date-parsing-exception/7716/6 "2012-05-21T08:35:58Z")

</div>

On Mon, May 21, 2012 at 10:03 AM, mkleen [mkleen@gmail.com](mailto:mkleen@gmail.com) wrote:

> On Sunday, May 20, 2012 10:22:41 PM UTC+2, kimchy wrote:
> 
> > Yes, the wildcard aspect is only supported for query\_string, as well as  
> > lenient. Its kindda tricky to support it in other elements, since it means  
> > compound queries (ones that inner parse the term query, like bool query)  
> > will need to know how to handle "null" queries.
> 
> Oh, does this mean a query\_string query should not be used in a compound  
> query ?

No, thats fine, just the other inner queries... .

---

<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:27am UTC](https://discuss.elastic.co/t/date-parsing-exception/7716/7 "2017-07-06T03:27:49Z")

</div>


