func deleteIndexFunc(c *cli.Context) { if len(c.Args()) > 0 { for _, name := range c.Args() { result, _ := common.SendToElastic(name, "DELETE", nil) log.Println(result) } } else { log.Println("Provide index name. e.g: index1, index2, ...") } }
// Sends data to elastic index func toElastic(indexName string, logType string, record interface{}) error { j, err := json.Marshal(record) if err != nil { log.Println("Error encoding message to JSON") } else { _, err := common.SendToElastic(fmt.Sprintf("%s/%s", indexName, logType), "POST", j) if err != nil { return err } } return nil }
func createIndexFunc(c *cli.Context) { settings := `{ "settings": { "index": { "number_of_shards": 5, "number_of_replicas": 1, "refresh_interval" : "2s" } } }` result, _ := common.SendToElastic(c.Args()[0], "PUT", []byte(settings)) log.Println(result) }
func createUsersIndexFunc(c *cli.Context) { log.Println("Creating users index in ElasticSearch") settings := `{ "settings": { "index": { "number_of_shards": 5, "number_of_replicas": 1, "refresh_interval" : "1s" } }, "mappings": { "user" : { "_source" : {"enabled" : true}, "properties" : { "email" : {"type" : "string", "index": "not_analyzed" }, "password" : {"type" : "string", "index": "not_analyzed" }, "apiKey" : {"type" : "string", "index": "not_analyzed" } } } } }` result, _ := common.SendToElastic("users", "PUT", []byte(settings)) log.Println(result) }