zincsearch/zincsearch · error

index.name should be not empty

Error message

index.name should be not empty

What it means

CreateIndexWorker validates that an index has a non-empty name before creating it in the core index store. If the parsed request body (newIndex.Name) is empty and no index name was supplied out-of-band (URL path or query param indexName), the handler refuses to create an index. This guards against nameless indices corrupting the in-memory index map.

Source

Thrown at pkg/handlers/index/create.go:105

		zutils.GinRenderJSON(c, http.StatusBadRequest, meta.HTTPResponseError{Error: err.Error()})
		return
	}

	zutils.GinRenderJSON(c, http.StatusOK, gin.H{
		"acknowledged":        true,
		"shards_acknowledged": true,
		"index":               newIndex.Name,
	})
}

func CreateIndexWorker(newIndex *meta.IndexSimple, indexName string) error {
	newIndex.StorageType = "disk"
	if newIndex.Name == "" && indexName != "" {
		newIndex.Name = indexName
	}

	if newIndex.Name == "" {
		return errors.New("index.name should be not empty")
	}

	if _, ok := core.GetIndex(newIndex.Name); ok {
		return errors.New("index [" + newIndex.Name + "] already exists")
	}

	if newIndex.Settings == nil {
		newIndex.Settings = new(meta.IndexSettings)
	}
	analyzers, err := zincanalysis.RequestAnalyzer(newIndex.Settings.Analysis)
	if err != nil {
		return errors.New(err.Error())
	}

	mappings, err := mappings.Request(analyzers, newIndex.Mappings)
	if err != nil {
		return errors.New(err.Error())
	}

View on GitHub (pinned to dd2f8afd65)

Solutions

  1. Add a non-empty "name" field to the index creation JSON body
  2. Pass the index name in the request path/query parameter so indexName fills it in
  3. Verify your HTTP client is not dropping the name field during JSON serialization

Example fix

// before
curl -X POST http://localhost:4080/api/index -d '{"storage_type":"disk"}'
// after
curl -X POST http://localhost:4080/api/index -d '{"name":"my-index","storage_type":"disk"}'
Defensive patterns

Strategy: validation

Validate before calling

const body = JSON.parse(requestBody);
if (!body.name || typeof body.name !== 'string' || body.name.trim() === '') {
  throw new Error('Index creation requires a non-empty "name" field');
}

Type guard

function hasValidIndexName(b) {
  return typeof b === 'object' && b !== null &&
    typeof b.name === 'string' && b.name.trim().length > 0;
}

Prevention

When it happens

Trigger: Calling POST /api/index with a JSON body that omits the "name" field (or sets it to ""), without providing an index name in the request path/query parameter.

Common situations: Copy-pasted curl bodies missing the name field; clients that send only settings/mappings; API wrappers that strip unknown JSON fields; using an endpoint variant where the name is expected in the URL but only the body was sent.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of zincsearch/zincsearch@dd2f8afd65 (2026-09-03). Data as JSON: /api/errors/a3f21755357488d5. Report an issue: GitHub.