Getting Error 502,{“ok”:false,”message”:”backend closed connection”} for enriching fields to another index

Viewed 1016

I have two index 1.ther 2.part. "ther" index has 24 fields, ''part" index has 19 fields. I have to enrich "ther" index with "part" index fields.

Field "user_id" is common between two indexes. Using enrich process I tried creating 3 rd index "part_ther"

get ther/_search
{
        "_index" : "ther",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "Ahi" : 42.6,
          "Index" : 90,
          "ipapPressureAverage" : 49,
          "MinuteVentAverage" : 20,
          "DeviceSerialNumber" : "<>",
          "ClearAirwayApneaIndex" : 72.26135463,
          "PeriodicBreathingTime" : 9311,
          "cpapPressure90Pct" : 22,
          "epapPressureAverage" : 73,
          "ipapPressure90Pct" : 27,
          "Usage" : 93904,
          "epapPressure90Pct" : 10,
          "AverageBreathRate" : 65,
          "@timestamp" : "2021-08-29T00:00:00.000+05:30",
          "user_id" : "39,476",
          "TrigBreathsPct" : 93,
          "cpapPressureAverage" : 29,
          "AverageExhaledTidalVolume" : 20,
          "DayStorageDate" : "29-08-2021",
          "UnintendedLeakageAverage" : 67.58
        }

get part/_search

{
        "_index" : "part",
        "_type" : "_doc",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "email" : "<>",
          "program_id" : 1849,
          "program_name" : "<> ",
          "scheduled_program_id" : 4765,
          "scheduled_program_name" : "<>",
          "scheduled_program_status" : 0,
          "experience_id" : 10129,
          "experience_name" : "<>",
          "response_id" : 364482,
          "user_id" : 39476,
          "firing_time" : "2021-09-19T09:28:51.000-04:00",
          "opened_at" : null,
          "participation_percentage" : 0,
          "status" : "<>",
          "created_at" : "2021-09-18T12:26:02.455-04:00",
          "updated_at" : "2021-09-19T09:30:04.228-04:00",
          "last_frame_completed_id" : null,
          "realm" : "affective-part-364482",
          "realms_organization_ids" : [
            "<>"
          ]
        }
      }

Using enrich process I tried creating 3 rd index "ther-part" so that all fields from "ther" index got enriched with "part" index.

Steps-

PUT /_enrich/policy/ther-policy
{
  "match": {
    "indices": "ther",
    "match_field": "user_id",
    "enrich_fields": ["Ahi","AverageBreatheRate","AverageExhaledTidalVolume","ClearAirwayApneaIndex","cpapPressureAverage","cpapPressure90Pct","DayStorageDate","epapPressureAverage","epapPressure90Pct","ipapPressureAverage","ipapPressure90Pct","MinuteVentAverage","PeriodicBreathingTime","TrigBreathsPct","UnintendedLeakageAverage","Usage","DeviceSerialNumber"]
  }
}
*****
Output-
{
  "acknowledged" : true
}

*************

POST /_enrich/policy/ther-policy/_execute
Output-
{
  "status" : {
    "phase" : "COMPLETE"
  }
}

*************************
PUT /_ingest/pipeline/ther_lookup
{
  "description" : "Enriching user details with tracks",
  "processors" : [
    {
      "enrich" : {
        "policy_name": "ther-policy",
        "field" : "user_id",
        "target_field": "tmp",
        "max_matches": "1"
      }
    },
    {
      "script": {
        "if": "ctx.tmp != null",
        "source": "ctx.putAll(ctx.tmp); ctx.remove('tmp');"
      }
    }
   ]
}
Output-
{
  "acknowledged" : true
}
**************************

POST _reindex
{
  "source": {
    "index": "part"
  },
  "dest": {
    "index": "part_ther",
    "pipeline": "ther_lookup"
    
  }
}

Fields are getting enriched in part_ther index. Index "part" and "ther" has only 2 docs as I am testing the enrichment processor.

get part_ther/_search
{
  "_index": "part_ther",
  "_type": "_doc",
  "_id": "1",
  "_score": 1,
  "_source": {
    "Ahi": 42.6,
    "response_id": 364482,
    "program_id": 1849,
    "program_name": "<> ",
    "created_at": "2021-09-18T12:26:02.455-04:00",
    "ipapPressureAverage": 49,
    "MinuteVentAverage": 20,
    "DeviceSerialNumber": "<>",
    "scheduled_program_id": 4765,
    "experience_id": 10129,
    "ClearAirwayApneaIndex": 72.26135463,
    "PeriodicBreathingTime": 9311,
    "updated_at": "2021-09-19T09:30:04.228-04:00",
    "scheduled_program_status": 0,
    "cpapPressure90Pct": 22,
    "email": "<>",
    "epapPressureAverage": 73,
    "ipapPressure90Pct": 27,
    "last_frame_completed_id": null,
    "Usage": 93904,
    "participation_percentage": 0,
    "epapPressure90Pct": 10,
    "firing_time": "2021-09-19T09:28:51.000-04:00",
    "opened_at": null,
    "realms_organization_ids": [
      "<>"
    ],
    "user_id": "39476",
    "scheduled_program_name": "<>",
    "TrigBreathsPct": 93,
    "cpapPressureAverage": 29,
    "experience_name": "<>",
    "AverageExhaledTidalVolume": 20,
    "DayStorageDate": "29-08-2021",
    "realm": "<>",
    "UnintendedLeakageAverage": 67.58,
    "status": "<>"
  }

In Original Index "therapy" index has 9k docs and "participation index" has 80k docs.

When I am trying to create third index on original indices, I am getting errors. Error 502, {"ok":false,"message":"backend closed connection"} How can I avoid this error and enrich indices successfully.

POST _reindex
{
  "source": {
    "index": "-participation"
  },
  "dest": {
    "index": "data-participation-therapy1",
    "pipeline": "therapy_lookup"
  }
}

output-
{"ok":false,"message":"backend closed connection"}

1 Answers

Thanks, @Val for clarifying this error.

backend closed connection simply means that the client (i.e. Kibana Dev Tools in your browser) timed out. But the reindex process is still ongoing in the background.

If your source index is big, odds are high that it will take longer than the timeout for the operation to terminate. So you should start your reindex to run asynchronously using

POST _reindex?wait_for_completion=false

The call will return immediately and give you a task ID which you can use to check the task status as it progresses using

GET _tasks/<task_id>

Ref link-Enrich fields in new index using enrich processor

Related