Skip to content

Commit

Permalink
fix: error when ingesting after index already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlougheed committed Nov 4, 2024
1 parent cc5cad8 commit 4ee4b80
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/api/services/ingestion.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,22 @@ func (i *IngestionService) ProcessVcf(
fmt.Printf("Got %d contigs: %v\n", len(contigs), contigs)
for _, c := range contigs {
var client = i.ElasticsearchClient
var contigIndex = variantIndexName(c)

res, err := client.Indices.Exists([]string{contigIndex})
if res.StatusCode == 404 {
mappings, _ := json.Marshal(indexes.VARIANT_INDEX_MAPPING)
res, _ := client.Indices.Create(
contigIndex,
client.Indices.Create.WithBody(strings.NewReader(fmt.Sprintf(`{"mappings": %s}`, mappings))),
)

mappings, _ := json.Marshal(indexes.VARIANT_INDEX_MAPPING)
res, _ := client.Indices.Create(
variantIndexName(c),
client.Indices.Create.WithBody(strings.NewReader(fmt.Sprintf(`{"mappings": %s}`, mappings))),
)

fmt.Printf("Creating contig index %s - got response: %s\n", c, res.String())
fmt.Printf("Creating contig index %s - got response: %s\n", c, res.String())
} else if err != nil {
fmt.Printf("Contig index %s existence-check got error: %s\n", c, err)
} else {
fmt.Printf("Contig index %s already exists; skipping creation\n", c)
}
}

discoveredHeaders = true
Expand Down

0 comments on commit 4ee4b80

Please sign in to comment.