Skip to content

Instantly share code, notes, and snippets.

@pzentenoe
Created July 23, 2019 13:51
Show Gist options
  • Save pzentenoe/dda3d7f40d438c04eef69e39a3aab90f to your computer and use it in GitHub Desktop.
Save pzentenoe/dda3d7f40d438c04eef69e39a3aab90f to your computer and use it in GitHub Desktop.
Crear archivo json para bulk en elastic
func CreateElasticIndexData(products []models.Product) error {
file, err := os.Create("archivo.json")
if err != nil {
fmt.Println(err)
return err
}
w := bufio.NewWriter(file)
defer file.Close()
for _, value := range products {
response := fmt.Sprintf(`{"index":{"_id":%s}}`, value.ItemNumber)
fmt.Fprintln(w, response)
productJson, _ := json.Marshal(value)
fmt.Fprintln(w, string(productJson))
}
return w.Flush()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment