# Error in string field

**URL:** <https://discuss.elastic.co/t/error-in-string-field/69403>\
**Category:** Elasticsearch\
**Created:** [December 19, 2016, 7:52am UTC](https://discuss.elastic.co/t/error-in-string-field/69403 "2016-12-19T07:52:22Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![madhan](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@madhan](https://discuss.elastic.co/u/madhan)\
**Post date:** [December 19, 2016, 7:52am UTC](https://discuss.elastic.co/t/error-in-string-field/69403/1 "2016-12-19T07:52:22Z")

</div>

Failed to parse [**searchtext**];  
nested: MapperParsingException[failed to parse date field [], tried both date format [dateOptionalTime], and timestamp number];  
nested: IllegalArgumentException[Invalid format: "".

I am getting the above error messsage while inserting docs with json data. The error field searchtext is of string datatype but it throwing exception as datetime.

i dont know what went wrong.. Advice to overcome this issue..

Its very urgent..

Thanks.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 19, 2016, 7:55am UTC](https://discuss.elastic.co/t/error-in-string-field/69403/2 "2016-12-19T07:55:07Z")

</div>

It looks like the field has been mapped as a date and you're trying to index a document where the field doesn't contain a date. If the field shouldn't be a date field you need to reindex. You should probably explicitly define the field as a string field to avoid having this happening again.

---

<div class="post-metadata">

**Author:** ![madhan](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@madhan](https://discuss.elastic.co/u/madhan)\
**Post date:** [December 19, 2016, 7:58am UTC](https://discuss.elastic.co/t/error-in-string-field/69403/3 "2016-12-19T07:58:30Z")

</div>

Thanks Magnusbaeck.

How to define that field as string field when i'm indexing docs using json data.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 19, 2016, 8:00am UTC](https://discuss.elastic.co/t/error-in-string-field/69403/4 "2016-12-19T08:00:45Z")

</div>

AFAIK you can't set the mapping of a field when you're indexing a document. Mappings are set either when you create the index (possibly implicitly via an index template) or with a put mapping API call (as long as the field whose mapping you're trying to define doesn't already exist).

---

<div class="post-metadata">

**Author:** ![madhan](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@madhan](https://discuss.elastic.co/u/madhan)\
**Post date:** [December 19, 2016, 8:11am UTC](https://discuss.elastic.co/t/error-in-string-field/69403/5 "2016-12-19T08:11:12Z")

</div>

Yeah, I understand.

Pls send any reference or example of how to create index with mapping using DSL.

Thanks.

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [December 19, 2016, 8:12am UTC](https://discuss.elastic.co/t/error-in-string-field/69403/6 "2016-12-19T08:12:01Z")

</div>

Please see the Elasticsearch documentation and feel free to come back with any specific questions.

---

<div class="post-metadata">

**Author:** ![madhan](https://avatars.discourse-cdn.com/v4/letter/m/aca169/32.png) [@madhan](https://discuss.elastic.co/u/madhan)\
**Post date:** [December 19, 2016, 8:14am UTC](https://discuss.elastic.co/t/error-in-string-field/69403/7 "2016-12-19T08:14:06Z")

</div>

Ok. Thanks for your response.

I will refer document and get back you.

Thanks.

---

<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:** [January 16, 2017, 8:14am UTC](https://discuss.elastic.co/t/error-in-string-field/69403/8 "2017-01-16T08:14:19Z")

</div>

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