{"record":{"id":"2f49a9ab7c7251f1","repo":"Tencent/WeKnora","slug":"invalid-hit-object-format","errorCode":null,"errorMessage":"invalid hit object format","messagePattern":"invalid hit object format","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/application/repository/retriever/elasticsearch/v7/repository.go","lineNumber":1158,"sourceCode":"\t\t}\n\t}\n\n\treturn indexInfoList, nil\n}\n\n// processSingleHit processes a single hit and creates index information\nfunc (e *elasticsearchRepository) processSingleHit(ctx context.Context,\n\thit interface{},\n\tsourceToTargetKBIDMap map[string]string,\n\tsourceToTargetChunkIDMap map[string]string,\n\ttargetKnowledgeBaseID string,\n) (*typesLocal.IndexInfo, []float32, error) {\n\tlog := logger.GetLogger(ctx)\n\n\thitMap, ok := hit.(map[string]interface{})\n\tif !ok {\n\t\tlog.Warnf(\"[ElasticsearchV7] Invalid hit object format\")\n\t\treturn nil, nil, fmt.Errorf(\"invalid hit object format\")\n\t}\n\n\t// Get document source\n\tsourceObj, ok := hitMap[\"_source\"].(map[string]interface{})\n\tif !ok {\n\t\tlog.Warnf(\"[ElasticsearchV7] Hit missing _source field\")\n\t\treturn nil, nil, fmt.Errorf(\"hit missing _source field\")\n\t}\n\n\t// Get source ChunkID and corresponding target ChunkID\n\tsourceChunkID, ok := sourceObj[\"chunk_id\"].(string)\n\tif !ok {\n\t\tlog.Warnf(\"[ElasticsearchV7] Source index data missing chunk_id field\")\n\t\treturn nil, nil, fmt.Errorf(\"source index data missing chunk_id field\")\n\t}\n\n\ttargetChunkID, ok := sourceToTargetChunkIDMap[sourceChunkID]\n\tif !ok {","sourceCodeStart":1140,"sourceCodeEnd":1176,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/application/repository/retriever/elasticsearch/v7/repository.go#L1140-L1176","documentation":"processSingleHit asserts each element of the hits list is a map[string]interface{}; if a hit is not a JSON object, the code logs a warning and returns this error, aborting the batch. It indicates a malformed element in the Elasticsearch search response's hits array during index copy.","triggerScenarios":"processSourceBatch → processSingleHit receives a hit that is not an object — e.g. the hits array contains scalars/arrays, or the previous layer mis-parsed the response so document objects were mangled.","commonSituations":"Corrupted or non-standard response body; a custom middleware/decoder altering JSON types (e.g. numbers-only elements); hitting a non-ES-compatible service whose hits array has unexpected element types.","solutions":["Dump the raw hits array and locate the malformed element to confirm the corruption source","Ensure decoding uses standard json.Unmarshal into map[string]interface{} without custom transforms","Verify the source index actually belongs to Elasticsearch and its mapping is intact","Skip-and-log bad hits instead of failing the whole batch if partial copy is acceptable"],"exampleFix":"// before\ninfo, vec, err := processSingleHit(hit)\nif err != nil { return err }\n// after: skip malformed hits\ninfo, vec, err := processSingleHit(hit)\nif err != nil {\n    log.Warnf(\"skipping malformed hit: %v\", err)\n    continue\n}","handlingStrategy":"type-guard","validationCode":"null","typeGuard":"func isHitObject(hit interface{}) (*map[string]interface{}, bool) {\n    m, ok := hit.(map[string]interface{})\n    if !ok { return nil, false }\n    return &m, true\n}","tryCatchPattern":"info, vec, err := processSingleHit(hit)\nif err != nil {\n    log.Warnf(\"skipping malformed hit: %v\", err)\n    continue // fail-soft per hit instead of aborting the batch\n}","preventionTips":["Decode responses with standard json.Unmarshal into interface{} so hits are maps","Validate a sample response shape before running full index copies","Skip-and-log malformed hits in migration jobs rather than failing wholesale","Alert on any 'invalid hit object format' warnings — they indicate upstream corruption"],"tags":["go","elasticsearch","migration","response-parsing"],"backgroundTag":"invalid-es-response-shape","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}