Created
April 7, 2019 05:42
-
-
Save tevin-morake/5475637bccff8b4346a6478903c7e1a6 to your computer and use it in GitHub Desktop.
How to create an elastic search index with default mappings
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
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