Created
July 23, 2019 13:51
-
-
Save pzentenoe/dda3d7f40d438c04eef69e39a3aab90f to your computer and use it in GitHub Desktop.
Crear archivo json para bulk en elastic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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