Skip to content
Oliver Eilhard edited this page Jan 3, 2016 · 10 revisions

The CreateIndex will create a new index.

// Create a new index.
mapping := `{
	"settings":{
		"number_of_shards":1,
		"number_of_replicas":0
	},
	"mappings":{
		"tweet":{
			"properties":{
				"tags":{
					"type":"string"
				},
				"location":{
					"type":"geo_point"
				},
				"suggest_field":{
					"type":"completion",
					"payloads":true
				}
			}
		}
	}
}`

createIndex, err := client.CreateIndex("twitter").BodyString(mapping).Do()
if err != nil {
    // Handle error
    panic(err)
}
if !createIndex.Acknowledged {
    // Not acknowledged
}

Notice that you can also use BodyJson(...) and provide an interface{} value to it (most probably a map[string]interface{}). It will be serialized to JSON and then used as the body of the request.

See the Create Index API documentation for more details.

Clone this wiki locally