Tencent/WeKnora · error

source index data missing knowledge_id field

Error message

source index data missing knowledge_id field

What it means

Elasticsearch v7 reindex guard: the hit's _source object lacks a string 'knowledge_id' field (missing or wrong type), so the owning document cannot be identified for KB remapping and the hit is rejected.

Source

Thrown at internal/application/repository/retriever/elasticsearch/v7/repository.go:1185

	// Get source ChunkID and corresponding target ChunkID
	sourceChunkID, ok := sourceObj["chunk_id"].(string)
	if !ok {
		log.Warnf("[ElasticsearchV7] Source index data missing chunk_id field")
		return nil, nil, fmt.Errorf("source index data missing chunk_id field")
	}

	targetChunkID, ok := sourceToTargetChunkIDMap[sourceChunkID]
	if !ok {
		log.Warnf("[ElasticsearchV7] Source chunk ID %s not found in mapping", sourceChunkID)
		return nil, nil, fmt.Errorf("source chunk ID %s not found in mapping", sourceChunkID)
	}

	// Get mapped target knowledge ID
	sourceKnowledgeID, ok := sourceObj["knowledge_id"].(string)
	if !ok {
		log.Warnf("[ElasticsearchV7] Source index data missing knowledge_id field")
		return nil, nil, fmt.Errorf("source index data missing knowledge_id field")
	}

	targetKnowledgeID, ok := sourceToTargetKBIDMap[sourceKnowledgeID]
	if !ok {
		log.Warnf("[ElasticsearchV7] Source knowledge ID %s not found in mapping", sourceKnowledgeID)
		return nil, nil, fmt.Errorf("source knowledge ID %s not found in mapping", sourceKnowledgeID)
	}

	// Extract basic content
	content, _ := sourceObj["content"].(string)
	originalSourceID, _ := sourceObj["source_id"].(string)
	sourceType := 0
	if st, ok := sourceObj["source_type"].(float64); ok {
		sourceType = int(st)
	}

	// Extract is_enabled (default true for backward compatibility)
	isEnabled := true

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Verify source index documents include knowledge_id
  2. Fix source ingestion so knowledge_id is stored as a string
  3. Skip and log hits lacking knowledge_id
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at internal/application/repository/retriever/elasticsearch/v7/repository.go:1185 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/75a67ffb6622bae3. Report an issue: GitHub.