# Elasticsearch - ingest pipeline - convert string field to integer

**URL:** <https://discuss.elastic.co/t/elasticsearch-ingest-pipeline-convert-string-field-to-integer/151579>\
**Category:** Elasticsearch\
**Created:** [October 9, 2018, 8:59am UTC](https://discuss.elastic.co/t/elasticsearch-ingest-pipeline-convert-string-field-to-integer/151579 "2018-10-09T08:59:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Orsius](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/orsius/32/13646_2.png) [@Orsius](https://discuss.elastic.co/u/Orsius)\
**Post date:** [October 9, 2018, 8:59am UTC](https://discuss.elastic.co/t/elasticsearch-ingest-pipeline-convert-string-field-to-integer/151579/1 "2018-10-09T08:59:33Z")

</div>

Dear Community Members,

- I have the following document in an index called raw\_marvel\_movies

```bash
$ cat 1doc.json |jq '._source'
{
  "year": "2015",
  "id": "4",
  "name": "Avengers: Age of Ultron",
  "Final box office ranks (billion)": 1.405,
  "Opening weekend box office (million)": 191.27
}
$ cat 1doc.json |jq '._source.id'
"4"

```

- want to convert the `_source.id` from string to integer
- in order to do so, I used an elasticsearch ingest pipeline and the `_reindex` API like so:

```auto
PUT _ingest/pipeline/convert_str2int_ingest_pipeline
{
  "description": "convert string to integer pipeline with handled exceptions",
  "version": 1,
  "processors": [
    {
      "convert": {
        "field": "_source.id",
        "type": "integer"
      }
    }
  ]
}
POST _reindex
{
  "source": {
    "index": "raw_marvel_movies"
  },
  "dest": {
    "index": "marvel_movies",
    "pipeline": "convert_str2int_ingest_pipeline"
  }
}

```

- why should I received the follow error response ? 😕 `unable to convert [id] to integer`

```auto
{
  "took": 172,
  "timed_out": false,
  "total": 48,
  "updated": 0,
  "created": 47,
  "deleted": 0,
  "batches": 1,
  "version_conflicts": 0,
  "noops": 0,
  "retries": {
    "bulk": 0,
    "search": 0
  },
  "throttled_millis": 0,
  "requests_per_second": -1,
  "throttled_until_millis": 0,
  "failures": [
    {
      "index": "marvel_movies3",
      "type": "doc",
      "id": "GN3JV2YBQcY2JSA-GX-Q",
      "cause": {
        "type": "exception",
        "reason": "java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: unable to convert [id] to integer",
        "caused_by": {
          "type": "illegal_argument_exception",
          "reason": "java.lang.IllegalArgumentException: unable to convert [id] to integer",
          "caused_by": {
            "type": "illegal_argument_exception",
            "reason": "unable to convert [id] to integer",
            "caused_by": {
              "type": "number_format_exception",
              "reason": "For input string: \"id\""
            }
          }
        },
        "header": {
          "processor_type": "convert"
        }
      },
      "status": 500
    }
  ]
}

```

I obviously doing something wrong here, it's probably the lack of caffeine, but I can not see what's wrong here 😕 because using the `_simulate`api, I don't get any errors :

```auto
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "convert": {
          "field": "_source.id",
          "type": "integer"
        }
      }
    ]
  },
  "docs": [
    {
      "_index": "marvel_movies",
      "_type": "doc",
      "_id": "Gd3JV2YBQcY2JSA-GX-Q",
      "_score": 1,
      "_source": {
        "year": "2015",
        "id": "4",
        "name": "Avengers: Age of Ultron",
        "final_box_office_ranks_billion": 1.405,
        "opening_weekend_box_office_million": 191.27
      }
    }
  ]
}

```

answer:

```auto
{
  "docs": [
    {
      "doc": {
        "_index": "marvel_movies",
        "_type": "doc",
        "_id": "Gd3JV2YBQcY2JSA-GX-Q",
        "_source": {
          "year": "2015",
          "final_box_office_ranks_billion": 1.405,
          "name": "Avengers: Age of Ultron",
          "id": 4,
          "opening_weekend_box_office_million": 191.27
        },
        "_ingest": {
          "timestamp": "2018-10-09T10:08:50.372Z"
        }
      }
    }
  ]
}

```

Here the _id_ field is well an _integer_

Any advices? Thanks in advance.

kr,

---

<div class="post-metadata">

**Author:** ![jakelandis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jakelandis/32/36163_2.png) [@jakelandis](https://discuss.elastic.co/u/jakelandis)\
**Post date:** [October 10, 2018, 8:39am UTC](https://discuss.elastic.co/t/elasticsearch-ingest-pipeline-convert-string-field-to-integer/151579/2 "2018-10-10T08:39:58Z")

</div>

If you get that document in error, what is the value for id ?

```auto
GET raw_marvel_movies/doc/GN3JV2YBQcY2JSA-GX-Q

```

Based on the error it looks like the document may have

```auto
"id": "id"

```

instead of an integer as string for the value .

---

<div class="post-metadata">

**Author:** ![Orsius](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/orsius/32/13646_2.png) [@Orsius](https://discuss.elastic.co/u/Orsius)\
**Post date:** [October 10, 2018, 8:55am UTC](https://discuss.elastic.co/t/elasticsearch-ingest-pipeline-convert-string-field-to-integer/151579/3 "2018-10-10T08:55:03Z")

</div>

Damned! You're right, stupid mistake I made, the dataset comes from a csv file and I indexed the header of the file ☹

Thanks for your answer and your time.

This topic can be closed.

---

<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:** [November 7, 2018, 9:02am UTC](https://discuss.elastic.co/t/elasticsearch-ingest-pipeline-convert-string-field-to-integer/151579/4 "2018-11-07T09:02:23Z")

</div>

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