// CreateField makes the named field in the named index with the given options.
// This method currently only takes a single functional option, but that may be
// changed in the future to support multiple options.
CreateField makes the named field in the named index with the given options.
This method currently only takes a single functional option, but that may be
changed in the future to support multiple options.
// CreateField makes the named field in the named index with the given options . // This method currently only takes a single functional option but that may be // changed in the future to support multiple options .
func (api *API) CreateField(ctx context.Context, indexName string, fieldName string, opts ...FieldOption) (*Field, error) {
	span, _ := tracing.StartSpanFromContext(ctx, "API.CreateField")
	defer span.Finish()
	if err := api.validate(apiCreateField); err != nil {
		return nil, errors.Wrap(err, "validating api method")
	}
	fo := FieldOptions{}
	for _, opt := range opts {
		err := opt(&fo)
		if err != nil {
			return nil, errors.Wrap(err, "applying option")
		}
	}
	index := api.holder.Index(indexName)
	if index == nil {
		return nil, newNotFoundError(ErrIndexNotFound)
	}
	field, err := index.CreateField(fieldName, opts...)
	if err != nil {
		return nil, errors.Wrap(err, "creating field")
	}
	err = api.server.SendSync(
		&CreateFieldMessage{
			Index: indexName,
			Field: fieldName,
			Meta:  &fo,
		})
	if err != nil {
		api.server.logger.Printf("problem sending CreateField message: %s", err)
		return nil, errors.Wrap(err, "sending CreateField message")
	}
	api.holder.Stats.CountWithCustomTags("createField", 1, 1.0, []string{fmt.Sprintf("index:%s", indexName)})
	return field, nil
}
func ( api * API ) CreateField ( ctx context . Context , indexName string , fieldName string , opts ... FieldOption ) ( * Field , error ) { span , _ := tracing . StartSpanFromContext ( ctx , " " ) defer span . Finish ( ) if err := api . validate ( apiCreateField ) ; err != nil { return nil , errors . Wrap ( err , " " ) } fo := FieldOptions { } for _ , opt := range opts { err := opt ( & fo ) if err != nil { return nil , errors . Wrap ( err , " " ) } } index := api . holder . Index ( indexName ) if index == nil { return nil , newNotFoundError ( ErrIndexNotFound ) } field , err := index . CreateField ( fieldName , opts ... ) if err != nil { return nil , errors . Wrap ( err , " " ) } err = api . server . SendSync ( & CreateFieldMessage { Index : indexName , Field : fieldName , Meta : & fo , } ) if err != nil { api . server . logger . Printf ( " " , err ) return nil , errors . Wrap ( err , " " ) } api . holder . Stats . CountWithCustomTags ( " " , 1 , 1.0 , [ ] string { fmt . Sprintf ( " " , indexName ) } ) return field , nil }
CreateField makes the named field in the named index with the given options.
CreateField makes the named field in the named index with the given options .
// Apply functional options. // Find index. // Create field. // Send the create field message to all nodes.