# Client request timeout

**URL:** <https://discuss.elastic.co/t/client-request-timeout/362622>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [July 5, 2024, 4:01pm UTC](https://discuss.elastic.co/t/client-request-timeout/362622 "2024-07-05T16:01:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shrm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shrm/32/131044_2.png) [@shrm](https://discuss.elastic.co/u/shrm)\
**Post date:** [July 5, 2024, 4:01pm UTC](https://discuss.elastic.co/t/client-request-timeout/362622/1 "2024-07-05T16:01:30Z")

</div>

I have an index with wrong datatype in an attribute "vjid"

I tried to convert "vjid" values from string to integer using this command:

```auto
POST vjdb/_update_by_query
{
  "script": {
    "source": "ctx._source.vjid = Integer.parseInt(ctx._source.vjid)",
    "lang": "painless"
  },
  "query": {
    "exists": {
      "field": "vjid"
    }
  }
}

```

it works perfectly but suddenly stops after tens of seconds with this message:

```auto
{
  "statusCode": 502,
  "error": "Bad Gateway",
  "message": "Client request timeout"
}

```

this is the input content of the index:

```auto
"hits": [
      {
        "_index": "vjdb",
        "_id": "uGhUGI8ByGfsded-LttS",
        "_score": 1,
        "_source": {
          "vjid": "12575001"
        }
      },
      {
        "_index": "vjdb",
        "_id": "uWhUGI8ByGfsded-LttS",
        "_score": 1,
        "_source": {
          "vjid": "12575271"
        }
      },...

```

and this is the correct output of the script:

```auto
"hits": [
      {
        "_index": "vjdb",
        "_id": "uGhUGI8ByGfsded-LttS",
        "_score": 1,
        "_source": {
          "vjid": 12575001
        }
      },
      {
        "_index": "vjdb",
        "_id": "uWhUGI8ByGfsded-LttS",
        "_score": 1,
        "_source": {
          "vjid": 12575271
        }
      },...

```

the output shows it is working nicely for the first 10K but at some point it terminated and the rest of the data is not converted.  
I tried to slice the input or increase the timeout but all failed. Do you know any successful method to convert all 20 million records with this code?

---

<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:** [July 5, 2024, 4:26pm UTC](https://discuss.elastic.co/t/client-request-timeout/362622/2 "2024-07-05T16:26:17Z")

</div>

From #Kibana to #Elasticsearch

---

<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:** [July 5, 2024, 4:27pm UTC](https://discuss.elastic.co/t/client-request-timeout/362622/3 "2024-07-05T16:27:31Z")

</div>

What is the mapping for this field? I guess it's a text right?  
In which case, what you are doing is not going to change anything but the json \_source content.

---

<div class="post-metadata">

**Author:** ![shrm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shrm/32/131044_2.png) [@shrm](https://discuss.elastic.co/u/shrm)\
**Post date:** [July 5, 2024, 8:55pm UTC](https://discuss.elastic.co/t/client-request-timeout/362622/4 "2024-07-05T20:55:07Z")

</div>

Yes, it is string in the mapping. But I need to convert it to integer.  
the code that I provided is able to fix it but it times out after a while of the execution and I cannot apply it on the entire indexed data.

---

<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:** [July 6, 2024, 7:15am UTC](https://discuss.elastic.co/t/client-request-timeout/362622/5 "2024-07-06T07:15:14Z")

</div>

If you need to convert it to integer because you want to filter by values or compute aggregations, what you are doing is not going to work.  
If the field is still a text, and not a int in the mapping.

So you need to create a new index and reindex your data. That's the best option IMO.

Look at the reindex API. And I would use an ingest pipeline with a convert processor to change your field from string to number on the fly, while reindexing.
