Skip to content

Instantly share code, notes, and snippets.

@tevin-morake
Created April 7, 2019 05:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tevin-morake/5475637bccff8b4346a6478903c7e1a6 to your computer and use it in GitHub Desktop.
Save tevin-morake/5475637bccff8b4346a6478903c7e1a6 to your computer and use it in GitHub Desktop.
How to create an elastic search index with default mappings
mapping := `{"settings":{"number_of_shards":1,"number_of_replicas":0},"mappings":{"cities":{"properties":{"CompanyName":{"type":"text"},"Addresses":{"type":"text"},"PostCode":{"type":"text"}}}}}`
elasticSURL := "https://xxxxxx"
client, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetURL(elasticSURL))
if err != nil {
// handle error
}
info, code, err := client.Ping(elasticSURL).Do(context.Background())
if err != nil {
// handle error
}
fmt.Printf("Elasticsearch returned with code %d and version %s | %v\n", code, info.Version.Number, loguuid)
if err := CreateElasticSearchIndex(client, "borderaccounts"), mapping); err != nil {
// handle error
}
func CreateElasticSearchIndex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment