{"record":{"id":"c1994e92646b61b2","repo":"mem0ai/mem0","slug":"opensearch-bulk-insert-failed-json-stringify-fa","errorCode":null,"errorMessage":"OpenSearch bulk insert failed: ${JSON.stringify(failedItem)}","messagePattern":"OpenSearch bulk insert failed: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/vector_stores/opensearch.ts","lineNumber":263,"sourceCode":"      ];\n    });\n\n    if (operations.length === 0) return;\n\n    const response = responseBody<{ errors?: boolean; items?: any[] }>(\n      await this.client.bulk({\n        refresh: this.autoRefresh,\n        body: operations,\n      }),\n    );\n\n    if (response.errors) {\n      const failedItem = response.items?.find((item) => {\n        const action = item.index || item.create || item.update || item.delete;\n        return action?.error;\n      });\n\n      throw new Error(\n        `OpenSearch bulk insert failed: ${JSON.stringify(failedItem)}`,\n      );\n    }\n  }\n\n  async keywordSearch(\n    query: string,\n    topK: number = 5,\n    filters?: SearchFilters,\n  ): Promise<VectorStoreResult[] | null> {\n    await this.initialize();\n    const boolQuery: Record<string, any> = {\n      should: [\n        { match: { \"payload.data\": query } },\n        { match: { \"payload.text_lemmatized\": query } },\n        { match: { \"payload.textLemmatized\": query } },\n      ],\n      minimum_should_match: 1,","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/vector_stores/opensearch.ts#L245-L281","documentation":"OpenSearch bulk insert returns per-item results; when response.errors is true the store finds the first item whose action (index/create/update/delete) carries an error object and throws it as JSON. This surfaces the server-side reason — mapping conflict, dimension mismatch at the server, parser failures, or index closed — instead of pretending the batch succeeded.","triggerScenarios":"A bulk insert where at least one document fails server-side: dense_vector of wrong dimension at the mapping level, malformed JSON payload fields, index readonly (disk watermark exceeded), or mapper_parsing_exception.","commonSituations":"Disk-full or watermark-triggered readonly index in self-hosted OpenSearch; mixed payload shapes in one batch; version upgrade of OpenSearch changing mapping strictness; partial failures hidden because only the first failed item is reported.","solutions":["Read the error field inside the reported item JSON (e.g. mapper_parsing_exception, illegal_argument_exception) — it names the real cause.","If the index is readonly (disk watermark): free disk space or adjust cluster.routing.allocation.disk.watermark settings, then retry.","If it is a vector dimension/mapping issue, recreate the index with the correct dimension and re-embed.","Retry only failed items rather than the whole batch to avoid duplicate work."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await store.insert(vectors, ids, payloads);\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('OpenSearch bulk insert failed:')) {\n    const item = JSON.parse(e.message.slice('OpenSearch bulk insert failed: '.length));\n    const err = item?.index?.error ?? item?.create?.error;\n    if (err?.type === 'cluster_block_exception') { /* free disk / clear readonly, then retry */ }\n    else throw e;\n  } else throw e;\n}","preventionTips":["Monitor cluster disk watermarks on self-hosted OpenSearch","Inspect the embedded error object before retrying","Retry only failed items; keep writes idempotent"],"tags":["opensearch","bulk-insert","mapping","partial-failure"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}