{"record":{"id":"b930dc74358a2c7d","repo":"Tencent/WeKnora","slug":"elasticsearch-update-by-query-failed-with-status","errorCode":null,"errorMessage":"elasticsearch update_by_query failed with status: %d","messagePattern":"elasticsearch update_by_query failed with status: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/repository/retriever/elasticsearch/v7/repository.go","lineNumber":1349,"sourceCode":"\t\t}\n\t\tqueryJSON, _ := json.Marshal(query)\n\t\tres, err := esapi.UpdateByQueryRequest{\n\t\t\tIndex: []string{e.index},\n\t\t\tBody:  strings.NewReader(string(queryJSON)),\n\t\t}.Do(ctx, e.client)\n\t\tif err != nil {\n\t\t\tlog.Errorf(\"[ElasticsearchV7] Failed to update enabled chunks: %v\", err)\n\t\t\treturn err\n\t\t}\n\t\tdefer res.Body.Close()\n\t\tif res.IsError() {\n\t\t\tvar e map[string]interface{}\n\t\t\tif err := json.NewDecoder(res.Body).Decode(&e); err != nil {\n\t\t\t\tlog.Errorf(\"[ElasticsearchV7] Error parsing the response body: %v\", err)\n\t\t\t} else {\n\t\t\t\tlog.Errorf(\"[ElasticsearchV7] Error updating enabled chunks: %v\", e[\"error\"])\n\t\t\t}\n\t\t\treturn fmt.Errorf(\"elasticsearch update_by_query failed with status: %d\", res.StatusCode)\n\t\t}\n\t\tlog.Infof(\"[ElasticsearchV7] Updated %d chunks to enabled\", len(enabledChunkIDs))\n\t}\n\n\t// Batch update disabled chunks using update_by_query\n\tif len(disabledChunkIDs) > 0 {\n\t\tquery := map[string]interface{}{\n\t\t\t\"query\": map[string]interface{}{\n\t\t\t\t\"terms\": map[string]interface{}{\n\t\t\t\t\te.idField(\"chunk_id\"): disabledChunkIDs,\n\t\t\t\t},\n\t\t\t},\n\t\t\t\"script\": map[string]interface{}{\n\t\t\t\t\"source\": \"ctx._source.is_enabled = false\",\n\t\t\t\t\"lang\":   \"painless\",\n\t\t\t},\n\t\t}\n\t\tqueryJSON, _ := json.Marshal(query)","sourceCodeStart":1331,"sourceCodeEnd":1367,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/repository/retriever/elasticsearch/v7/repository.go#L1331-L1367","documentation":"Elasticsearch v7 update_by_query API returned an HTTP error status while batch-updating chunk enabled flags: the response body was decoded for details, but the overall bulk update failed and the error is propagated to the caller.","triggerScenarios":"Thrown at internal/application/repository/retriever/elasticsearch/v7/repository.go:1349 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the logged response body for the ES error reason","Check index health and mapping compatibility","Retry update_by_query after resolving conflicts/version issues"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}