# Python bulk insert customize date parser

**URL:** https://discuss.elastic.co/t/python-bulk-insert-customize-date-parser/294113
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [January 12, 2022, 5:49am UTC](https://discuss.elastic.co/t/python-bulk-insert-customize-date-parser/294113 "2022-01-12T05:49:46Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![StevenZL](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@StevenZL](https://discuss.elastic.co/u/StevenZL)
#### Post date: [January 12, 2022, 5:49am UTC](https://discuss.elastic.co/t/python-bulk-insert-customize-date-parser/294113/1 "2022-01-12T05:49:46Z")

</div>

Hi all,

I'm new to Elasticsearch and I'm trying to bulk-insert into Elasticsearch using python  
After I read in the data using pandas, I created an index:

```auto
es = Elasticsearch()
es.indices.create(
        index="cars",
        mappings={
            "properties": {
                "manufacture_year": {
                    "type": "date",
                },
                "engine_displacement": {
                    "type": "date",
                },
                "date_created": {
                    "type": "date",
                    "format": ["yyyy-MM-dd HH:mm:ss.SSSSSSZ"]
                },
                "date_last_seen": {
                    "type": "date",
                    "format": ["yyyy-MM-dd HH:mm:ss.SSSSSZ"]
                }
            }
        }
    )

```

But I got errors when I was bulk-inserting and the errors were on date\_created and date\_last\_seen  
date\_created sample: 2015-11-14 18:10:06.838319+00  
date\_last\_seen sample: 2016-01-27 20:40:15.46361+00

**'type': 'illegal\_argument\_exception', 'reason': 'failed to parse date field [2015-11-14 18:10:06.838319+00] with format [[yyyy-MM-dd HH:mm:ss.SSSSSSZ]]', 'caused\_by': {'type': 'date\_time\_parse\_exception', 'reason': "Text '2015-11-14 18:10:06.838319+00' could not be parsed, unparsed text found at index 0**

what is that "unparsed text found at index 0"? I can't find any errors at index 0

Best Wishes  
Steven Zeng

---

<div class="post-metadata">

### Author: ![StevenZL](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@StevenZL](https://discuss.elastic.co/u/StevenZL)
#### Post date: [January 12, 2022, 7:12am UTC](https://discuss.elastic.co/t/python-bulk-insert-customize-date-parser/294113/2 "2022-01-12T07:12:49Z")

</div>

If I clean the data more and set the mappting to:

```auto
"date_created": {
                        "type": "date",
                        "format": ["yyyy-MM-dd HH:mm:ss"]
                        # "format": ["yyyy-MM-dd HH:mm:ss.SSSSSSZ"]
}

```

and cut the part after "." when yeilding the json data:

```auto
        j["date_created"] = str(j["date_created"]).split(".")[0]

```

everything will work fine, But I do want to keep the last part, what should I do?

---

<div class="post-metadata">

### Author: ![StevenZL](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@StevenZL](https://discuss.elastic.co/u/StevenZL)
#### Post date: [January 14, 2022, 7:49am UTC](https://discuss.elastic.co/t/python-bulk-insert-customize-date-parser/294113/3 "2022-01-14T07:49:10Z")

</div>

If I create an index directly in Elasticsearch

```auto
PUT /test
{
  "mappings": {
    "properties": {
      "date_created":{
        "type":"date"
        , "format": ["yyyy-MM-dd HH:mm:ss","yyyy-MM-dd HH:mm:ss.SSSSSSZ"]
      }
    }
  }
}

```

both posts works:

```auto
POST /test/_doc
{
  "created_date":"2015-11-14 18:10:06.838319+00"
}

```

and

```auto
POST /test/_doc
{
  "created_date":"2015-11-14 18:10:06"
}

```

It seems to me the only solution now is to write the request code myself, hopefully the bug in python client will be fixed soon.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [January 14, 2022, 8:39am UTC](https://discuss.elastic.co/t/python-bulk-insert-customize-date-parser/294113/4 "2022-01-14T08:39:57Z")

</div>

This looks weird to me. I'm not a Python expert.

Looking at the logs, it sounds like you are doing the same thing in Python and in Kibana Dev Console.

Could you create a full reproduction of this, with:

- The Kibana Dev Console script that you shared. Just add the `DELETE test` in front of it
- A full Python script which reproduces the exact same steps, and not using bulk.

And then report at [GitHub - elastic/elasticsearch-py: Official Elasticsearch client library for Python](https://github.com/elastic/elasticsearch-py)?

Unless @sethmlarson knows what is happening? 😉

---

<div class="post-metadata">

### Author: ![StevenZL](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@StevenZL](https://discuss.elastic.co/u/StevenZL)
#### Post date: [January 14, 2022, 12:56pm UTC](https://discuss.elastic.co/t/python-bulk-insert-customize-date-parser/294113/5 "2022-01-14T12:56:02Z")

</div>

Thanks,I've already reported it

---

<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: [February 11, 2022, 12:56pm UTC](https://discuss.elastic.co/t/python-bulk-insert-customize-date-parser/294113/6 "2022-02-11T12:56:56Z")

</div>

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