# How Update Type of field or Update all values of field

**URL:** <https://discuss.elastic.co/t/how-update-type-of-field-or-update-all-values-of-field/218760>\
**Category:** Elasticsearch\
**Created:** [February 11, 2020, 11:40am UTC](https://discuss.elastic.co/t/how-update-type-of-field-or-update-all-values-of-field/218760 "2020-02-11T11:40:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![thewasta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thewasta/32/48818_2.png) [@thewasta](https://discuss.elastic.co/u/thewasta)\
**Post date:** [February 11, 2020, 11:40am UTC](https://discuss.elastic.co/t/how-update-type-of-field-or-update-all-values-of-field/218760/1 "2020-02-11T11:40:33Z")

</div>

Hello there! This is the current mappings for a index, and I want to update/edit date field from text to date

> GET testing/\_search

```auto
        "mappings" : {
      "inventory" : {
        "properties" : {
          "date" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "productId" : {
            "type" : "long"
          },
          "skuId" : {
            "type" : "long"
          },
          "stock" : {
            "properties" : {
              "quantity" : {
                "type" : "long"
              },
              "warehouse" : {
                "type" : "long"
              }
            }
          },
          "values" : {
            "type" : "long"
          }
        }
      }
    },

```

Everytime I try to update it

> PUT testing/\_mapping/inventory

```auto
{
  "properties": {
    "date":{
      "type": "date",
      "format": "date hour_minute_second"
    }
  }
}

```

but return error

> {  
> "error": {  
> "root\_cause": [  
> {  
> "type": "illegal\_argument\_exception",  
> "reason": "Invalid format: [date hour\_minute\_second]: Illegal pattern component: t"  
> }  
> ],  
> "type": "illegal\_argument\_exception",  
> "reason": "Invalid format: [date hour\_minute\_second]: Illegal pattern component: t",  
> "caused\_by": {  
> "type": "illegal\_argument\_exception",  
> "reason": "Illegal pattern component: t"  
> }  
> },  
> "status": 400  
> }

I think the problem is because the value is '2020-02-25 12:12:12' so I tried with format

> Y-m-d H:m:s

But return error

> mapper [date] of different type, current\_type [text], merged\_type [date]

Maybe the problem is because I didn't save the date with 'T' word, in this case how can I update all values to include a 'T' between date and time? Any idea or advice to fix my fail?  
I can't reset the index and start again....  
Thanks

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [February 11, 2020, 11:54am UTC](https://discuss.elastic.co/t/how-update-type-of-field-or-update-all-values-of-field/218760/2 "2020-02-11T11:54:13Z")

</div>

> [@thewasta](#):
>
> I want to update/edit date field from text to date

The mapping for a field cannot be changed from `text` to `date`; you will need to [reindex](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html) data into a new index that has the `"date"` field set as a `date` data type.

Take a look at the [built-in formats for date](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html#built-in-date-formats); there's probably an existing format (or formats; multiple can be specified using `||` separator) that you can use.

---

<div class="post-metadata">

**Author:** ![thewasta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thewasta/32/48818_2.png) [@thewasta](https://discuss.elastic.co/u/thewasta)\
**Post date:** [February 11, 2020, 12:42pm UTC](https://discuss.elastic.co/t/how-update-type-of-field-or-update-all-values-of-field/218760/3 "2020-02-11T12:42:37Z")

</div>

Thanks. I don't know why in previous attempts it didn't work and always just return

> can't merge type [date] in [text]

I was creating a new template with `index_patterns` for the new index e.g

> "index\_patterns": [  
> "clone\_testing"  
> ],

After this... I made reindex

> POST \_reindex  
> {  
> "source": {  
> "index": "testing"  
> },  
> "dest": {  
> "index": "clone\_testing"  
> }  
> }

Nevermind thanks!

---

<div class="post-metadata">

**Author:** ![thewasta](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thewasta/32/48818_2.png) [@thewasta](https://discuss.elastic.co/u/thewasta)\
**Post date:** [February 14, 2020, 9:34am UTC](https://discuss.elastic.co/t/how-update-type-of-field-or-update-all-values-of-field/218760/4 "2020-02-14T09:34:07Z")

</div>

Hey! Apologize for typing back.  
The solution doesn't work. I'm trying to filter by range but returns values which doesn't correspond with the expected.  
I created a template:

> Put \_template/sku\_template

```auto
    "index_patterns" : [
      "sku"
    ],
    "mappings" : {
      "inventory" : {
        "properties" : {
          "skuId" : {
            "type" : "long"
          },
          "date" : {
            "type" : "date",
            "format" : "Y-m-d H:m:s"
          },
          "productId" : {
            "type" : "long"
          },
          "values" : {
            "type" : "long"
          },
          "stock" : {
            "properties" : {
              "quantity" : {
                "type" : "long"
              },
              "warehouse" : {
                "type" : "long"
              }
            }
          }
        }
      }
    },

```

Next

> POST \_reindex

```auto
POST _reindex
{
  "source": {
    "index": "sku_copy"
  },
  "dest": {
    "index": "sku"
  }
}

```

> GET sku/\_search

```auto
{
        "_index" : "sku",
        "_type" : "inventory",
        "_id" : "j9C-tW8BAn4d18TtXnWO",
        "_score" : 1.0,
        "_source" : {
          "skuId" : 1234,
          "productId" : 1234,
          "values" : [
            1
          ],
          "stock" : {
            "quantity" : 1,
            "warehouse" : 1
          },
          "date" : "2020-01-17 12:12:12"
        }
      },

```

This is one result, to see the date format.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [February 21, 2020, 5:16am UTC](https://discuss.elastic.co/t/how-update-type-of-field-or-update-all-values-of-field/218760/5 "2020-02-21T05:16:21Z")

</div>

> [@thewasta](#):
>
> ```auto
> "format" : "Y-m-d H:m:s"
> 
> ```

I don't think this format would match for `"date" : "2020-01-17 12:12:12"`. The response from the \_reindex call indicates how many documents were created and failed - did the response indicate failures when attempting to parse dates with the format?

The value that you specify for [`"format"`](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html) in the mapping is the one that Elasticsearch uses to _ **parse** _ the incoming date string. Based on the example provided, I think the format you want is

```auto
"format" : "YYYY-MM-dd HH:mm:ss"

```

---

<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:** [March 20, 2020, 5:16am UTC](https://discuss.elastic.co/t/how-update-type-of-field-or-update-all-values-of-field/218760/6 "2020-03-20T05:16:30Z")

</div>

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