From 87642d2620d93a8814adca3d1fe66481946e5b14 Mon Sep 17 00:00:00 2001 From: David Lougheed Date: Thu, 31 Oct 2024 14:36:55 -0400 Subject: [PATCH] fix(ingestion): create contig indices once after final header line found --- src/api/services/ingestion.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/api/services/ingestion.go b/src/api/services/ingestion.go index ca2dc62..4eb1569 100644 --- a/src/api/services/ingestion.go +++ b/src/api/services/ingestion.go @@ -408,27 +408,27 @@ func (i *IngestionService) ProcessVcf( } } - discoveredHeaders = true + // If we got to the VCF final header line, we've found all the contigs possible + // --> create required indices with mappings to ensure ES types are consistent + fmt.Printf("Got %d contigs: %v\n", len(contigs), contigs) + for _, c := range contigs { + var client = i.ElasticsearchClient + + mappings, _ := json.Marshal(indexes.VARIANT_INDEX_MAPPING) + var createBody = fmt.Sprintf(`{"mappings": %s}`, mappings) + + client.Indices.Create( + variantIndexName(c), + client.Indices.Create.WithBody(strings.NewReader(createBody)), + ) + } fmt.Println("Found the headers: ", headers) - continue + discoveredHeaders = true } continue } - // Create required indices with mappings to ensure ES types are cosnsitent - for _, c := range contigs { - var client = i.ElasticsearchClient - - mappings, _ := json.Marshal(indexes.VARIANT_INDEX_MAPPING) - var createBody = fmt.Sprintf(`{"mappings": %s}`, mappings) - - client.Indices.Create( - variantIndexName(c), - client.Indices.Create.WithBody(strings.NewReader(createBody)), - ) - } - // take a spot in the queue lineProcessingQueue <- true _fileWG.Add(1)