Index StructArray Fields
Public PreviewCreate indexes on StructArray subfields before you run vector search or accelerate scalar filtering. For a StructArray field, the index target is a subfield path, such as chunks[emb_list_vector], chunks[emb], or chunks[section].
This page uses the tech_articles collection from Create a StructArray Field. The chunks StructArray field contains scalar subfields for filtering and vector subfields for search.
Before you begin
Make sure the collection schema already contains the chunks StructArray field. Reuse the initialized client from Create a StructArray Field for your selected language (cli and ctx for Go, client for the other SDKs). You can create indexes before inserting data.
| Subfield path | Type | Index purpose |
|---|---|---|
chunks[emb_list_vector] | FLOAT_VECTOR | EmbeddingList search with MAX_SIM* metrics. |
chunks[emb] | FLOAT_VECTOR | Element-level search with regular vector metrics. |
chunks[section] | VARCHAR | Categorical filtering. |
chunks[quality_score] | FLOAT | Numeric filtering and range-style predicates. |
chunks[has_code] | BOOL | Boolean filtering. |
A vector field or vector subfield accepts only one index. If you need both EmbeddingList search and element-level search, create two separate vector subfields and index them separately. In this page, chunks[emb_list_vector] is indexed for EmbeddingList search, and chunks[emb] is indexed for element-level search.
Choose indexes
Use the search mode to choose the vector metric family.
| Search or filter goal | Target path | What to choose |
|---|---|---|
| EmbeddingList search | chunks[emb_list_vector] | A MAX_SIM* metric family. |
| Element-level vector search | chunks[emb] | A regular vector metric family, such as COSINE, IP, or L2. |
| Filter by string or category | chunks[section] | A scalar index supported by your target. |
| Filter by numeric range | chunks[quality_score], chunks[page] | A scalar index supported by your target. |
| Filter by boolean value | chunks[has_code] | A scalar index supported by your target. |
EmbeddingList search treats the vectors in a StructArray vector subfield as an embedding list and returns entity-level results. Element-level search searches each Struct element independently and can return the matched element offset.
Create vector indexes
The following example creates two vector indexes. The first index uses a MAX_SIM* metric for EmbeddingList search. The second index uses a regular vector metric for element-level search.
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
index_params = client.prepare_index_params()
# Index for EmbeddingList search.
index_params.add_index(
field_name="chunks[emb_list_vector]",
index_name="chunks_emb_list_max_sim",
index_type="AUTOINDEX",
metric_type="MAX_SIM_COSINE",
)
# Index for element-level search.
index_params.add_index(
field_name="chunks[emb]",
index_name="chunks_emb_cosine",
index_type="AUTOINDEX",
metric_type="COSINE",
)
client.create_index(
collection_name="tech_articles",
index_params=index_params,
)
import io.milvus.v2.common.IndexParam;
import io.milvus.v2.service.index.request.CreateIndexReq;
import java.util.Arrays;
client.createIndex(CreateIndexReq.builder()
.collectionName("tech_articles")
.indexParams(Arrays.asList(
IndexParam.builder().fieldName("chunks[emb_list_vector]")
.indexType(IndexParam.IndexType.AUTOINDEX)
.metricType(IndexParam.MetricType.MAX_SIM_COSINE)
.indexName("chunks_emb_list_max_sim")
.build(),
IndexParam.builder().fieldName("chunks[emb]")
.indexType(IndexParam.IndexType.AUTOINDEX)
.metricType(IndexParam.MetricType.COSINE)
.indexName("chunks_emb_cosine")
.build()))
.build());
import (
"fmt"
"github.com/milvus-io/milvus/client/v3/entity"
"github.com/milvus-io/milvus/client/v3/index"
"github.com/milvus-io/milvus/client/v3/milvusclient"
)
_, err = cli.CreateIndex(ctx, milvusclient.NewCreateIndexOption("tech_articles", "chunks[emb_list_vector]", index.NewAutoIndex(entity.MaxSimCosine)).WithIndexName("chunks_emb_list_max_sim"))
if err != nil {
fmt.Println(err.Error())
return
}
_, err = cli.CreateIndex(ctx, milvusclient.NewCreateIndexOption("tech_articles", "chunks[emb]", index.NewAutoIndex(entity.COSINE)).WithIndexName("chunks_emb_cosine"))
if err != nil {
fmt.Println(err.Error())
return
}
use milvus::v2::prelude::*;
let request = CreateIndexRequest::builder()
.collection_name("tech_articles")
.index_params(vec![
IndexParam::new().field_name("chunks[emb_list_vector]")
.index_name("chunks_emb_list_max_sim")
.index_type(IndexType::AutoIndex)
.metric_type(MetricType::MaxSimCosine),
IndexParam::new().field_name("chunks[emb]")
.index_name("chunks_emb_cosine")
.index_type(IndexType::AutoIndex)
.metric_type(MetricType::Cosine),
])
.build()?;
client.create_index(request).await?;
#include <stdexcept>
#include <iostream>
#include "milvus/MilvusClientV2.h"
milvus::IndexDesc emb_list_index("chunks[emb_list_vector]", "chunks_emb_list_max_sim",
milvus::IndexType::AUTOINDEX, milvus::MetricType::MAX_SIM_COSINE);
milvus::IndexDesc emb_index("chunks[emb]", "chunks_emb_cosine",
milvus::IndexType::AUTOINDEX, milvus::MetricType::COSINE);
milvus::CreateIndexRequest vector_request;
vector_request.WithCollectionName("tech_articles");
vector_request.WithIndexes({emb_list_index, emb_index});
status = client->CreateIndex(vector_request);
if (!status.IsOk()) {
throw std::runtime_error(status.Message());
}
await client.createIndex({
collection_name: "tech_articles",
field_name: "chunks[emb_list_vector]",
index_name: "chunks_emb_list_max_sim",
index_type: "AUTOINDEX",
metric_type: "MAX_SIM_COSINE",
});
await client.createIndex({
collection_name: "tech_articles",
field_name: "chunks[emb]",
index_name: "chunks_emb_cosine",
index_type: "AUTOINDEX",
metric_type: "COSINE",
});
using Milvus.Client.V2.Requests.Index;
using Milvus.Client.V2.Types;
await client.CreateIndexAsync(new CreateIndexReq
{
CollectionName = "tech_articles",
Indexes = new[]
{
new IndexParam("chunks[emb_list_vector]", "chunks_emb_list_max_sim", IndexType.AutoIndex, MetricType.MaxSimCosine),
new IndexParam("chunks[emb]", "chunks_emb_cosine", IndexType.AutoIndex, MetricType.Cosine)
}
});
curl --request POST \
--url "YOUR_CLUSTER_ENDPOINT/v2/vectordb/indexes/create" \
--header "Authorization: Bearer YOUR_CLUSTER_TOKEN" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "tech_articles",
"indexParams": [
{
"fieldName": "chunks[emb_list_vector]",
"indexName": "chunks_emb_list_max_sim",
"metricType": "MAX_SIM_COSINE",
"params": { "index_type": "AUTOINDEX" }
},
{
"fieldName": "chunks[emb]",
"indexName": "chunks_emb_cosine",
"metricType": "COSINE",
"params": { "index_type": "AUTOINDEX" }
}
]
}'
Warning
Do not create a MAX_SIM* index and a regular vector-metric index on the same vector subfield. If both search modes are required, write vectors to two separate vector subfields and create one index on each subfield.
Create scalar indexes
Create scalar indexes on StructArray scalar subfields when you use them in filters. Use the same structArray[subfield] path syntax.
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
index_params = client.prepare_index_params()
index_params.add_index(
field_name="chunks[section]",
index_name="chunks_section_inverted",
index_type="AUTOINDEX",
)
index_params.add_index(
field_name="chunks[has_code]",
index_name="chunks_has_code_inverted",
index_type="AUTOINDEX",
)
index_params.add_index(
field_name="chunks[quality_score]",
index_name="chunks_quality_score_sort",
index_type="AUTOINDEX",
)
index_params.add_index(
field_name="chunks[page]",
index_name="chunks_page_sort",
index_type="AUTOINDEX",
)
client.create_index(
collection_name="tech_articles",
index_params=index_params,
)
import io.milvus.v2.common.IndexParam;
import io.milvus.v2.service.index.request.CreateIndexReq;
import java.util.Arrays;
client.createIndex(CreateIndexReq.builder()
.collectionName("tech_articles")
.indexParams(Arrays.asList(
IndexParam.builder().fieldName("chunks[section]").indexType(IndexParam.IndexType.AUTOINDEX)
.indexName("chunks_section_inverted").build(),
IndexParam.builder().fieldName("chunks[has_code]").indexType(IndexParam.IndexType.AUTOINDEX)
.indexName("chunks_has_code_inverted").build(),
IndexParam.builder().fieldName("chunks[quality_score]").indexType(IndexParam.IndexType.AUTOINDEX)
.indexName("chunks_quality_score_sort").build(),
IndexParam.builder().fieldName("chunks[page]").indexType(IndexParam.IndexType.AUTOINDEX)
.indexName("chunks_page_sort").build()))
.build());
import (
"fmt"
"github.com/milvus-io/milvus/client/v3/entity"
"github.com/milvus-io/milvus/client/v3/index"
"github.com/milvus-io/milvus/client/v3/milvusclient"
)
_, err = cli.CreateIndex(ctx, milvusclient.NewCreateIndexOption("tech_articles", "chunks[section]", index.NewAutoIndex(entity.MetricType(""))).WithIndexName("chunks_section_inverted"))
if err != nil {
fmt.Println(err.Error())
return
}
_, err = cli.CreateIndex(ctx, milvusclient.NewCreateIndexOption("tech_articles", "chunks[has_code]", index.NewAutoIndex(entity.MetricType(""))).WithIndexName("chunks_has_code_inverted"))
if err != nil {
fmt.Println(err.Error())
return
}
_, err = cli.CreateIndex(ctx, milvusclient.NewCreateIndexOption("tech_articles", "chunks[quality_score]", index.NewAutoIndex(entity.MetricType(""))).WithIndexName("chunks_quality_score_sort"))
if err != nil {
fmt.Println(err.Error())
return
}
_, err = cli.CreateIndex(ctx, milvusclient.NewCreateIndexOption("tech_articles", "chunks[page]", index.NewAutoIndex(entity.MetricType(""))).WithIndexName("chunks_page_sort"))
if err != nil {
fmt.Println(err.Error())
return
}
use milvus::v2::prelude::*;
let request = CreateIndexRequest::builder()
.collection_name("tech_articles")
.index_params(vec![
IndexParam::new().field_name("chunks[section]").index_name("chunks_section_inverted").index_type(IndexType::AutoIndex),
IndexParam::new().field_name("chunks[has_code]").index_name("chunks_has_code_inverted").index_type(IndexType::AutoIndex),
IndexParam::new().field_name("chunks[quality_score]").index_name("chunks_quality_score_sort").index_type(IndexType::AutoIndex),
IndexParam::new().field_name("chunks[page]").index_name("chunks_page_sort").index_type(IndexType::AutoIndex),
])
.build()?;
client.create_index(request).await?;
#include <stdexcept>
#include <iostream>
#include "milvus/MilvusClientV2.h"
milvus::IndexDesc section_index("chunks[section]", "chunks_section_inverted",
milvus::IndexType::AUTOINDEX);
milvus::IndexDesc has_code_index("chunks[has_code]", "chunks_has_code_inverted",
milvus::IndexType::AUTOINDEX);
milvus::IndexDesc quality_index("chunks[quality_score]", "chunks_quality_score_sort",
milvus::IndexType::AUTOINDEX);
milvus::IndexDesc page_index("chunks[page]", "chunks_page_sort",
milvus::IndexType::AUTOINDEX);
milvus::CreateIndexRequest scalar_request;
scalar_request.WithCollectionName("tech_articles");
scalar_request.WithIndexes({section_index, has_code_index, quality_index, page_index});
status = client->CreateIndex(scalar_request);
if (!status.IsOk()) {
throw std::runtime_error(status.Message());
}
await client.createIndex({
collection_name: "tech_articles",
field_name: "chunks[section]",
index_name: "chunks_section_inverted",
index_type: "AUTOINDEX",
});
await client.createIndex({
collection_name: "tech_articles",
field_name: "chunks[has_code]",
index_name: "chunks_has_code_inverted",
index_type: "AUTOINDEX",
});
await client.createIndex({
collection_name: "tech_articles",
field_name: "chunks[quality_score]",
index_name: "chunks_quality_score_sort",
index_type: "AUTOINDEX",
});
await client.createIndex({
collection_name: "tech_articles",
field_name: "chunks[page]",
index_name: "chunks_page_sort",
index_type: "AUTOINDEX",
});
using Milvus.Client.V2.Requests.Index;
using Milvus.Client.V2.Types;
await client.CreateIndexAsync(new CreateIndexReq
{
CollectionName = "tech_articles",
Indexes = new[]
{
new IndexParam("chunks[section]", "chunks_section_inverted", IndexType.AutoIndex),
new IndexParam("chunks[has_code]", "chunks_has_code_inverted", IndexType.AutoIndex),
new IndexParam("chunks[quality_score]", "chunks_quality_score_sort", IndexType.AutoIndex),
new IndexParam("chunks[page]", "chunks_page_sort", IndexType.AutoIndex)
}
});
curl --request POST \
--url "YOUR_CLUSTER_ENDPOINT/v2/vectordb/indexes/create" \
--header "Authorization: Bearer YOUR_CLUSTER_TOKEN" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "tech_articles",
"indexParams": [
{ "fieldName": "chunks[section]", "indexName": "chunks_section_inverted", "params": { "index_type": "AUTOINDEX" } },
{ "fieldName": "chunks[has_code]", "indexName": "chunks_has_code_inverted", "params": { "index_type": "AUTOINDEX" } },
{ "fieldName": "chunks[quality_score]", "indexName": "chunks_quality_score_sort", "params": { "index_type": "AUTOINDEX" } },
{ "fieldName": "chunks[page]", "indexName": "chunks_page_sort", "params": { "index_type": "AUTOINDEX" } }
]
}'
Scalar indexes are optional but useful when StructArray scalar subfields appear frequently in filters, such as element_filter(chunks, $[quality_score] > 0.9) or MATCH_ANY(chunks, $[section] == "index").
Applicable metric types
For EmbeddingList search, choose the MAX_SIM* metric corresponding to the per-vector comparison: MAX_SIM_COSINE (also named MAX_SIM), MAX_SIM_IP, or MAX_SIM_L2 for dense vectors, and MAX_SIM_HAMMING or MAX_SIM_JACCARD for binary vectors. These metrics compare embedding lists and return entity-level results. For element-level search, use the corresponding regular metric listed below.
Scalar indexes are not supported on element-nullable subfields or on scalar ARRAY subfields. Filters on these subfields run without an index.
Index element-nullable and added vector subfields
A vector subfield can be created with element-level null (nullable=True), and a vector subfield can be added to an existing StructArray field. Both cases change how you index the subfield:
- An element-nullable vector subfield supports element-level search only. Index it with a regular vector metric such as
COSINE,IP, orL2.MAX_SIM*metrics and EmbeddingList indexes are rejected on it, andAUTOINDEXdoes not select aMAX_SIM*metric for it. Null vectors are skipped when the index is built and during search.
index_params = client.prepare_index_params()
# Element-level index on an added, element-nullable vector subfield.
index_params.add_index(
field_name="chunks[summary_emb]",
index_name="chunks_summary_emb_cosine",
index_type="HNSW",
metric_type="COSINE",
params={
"M": 16,
"efConstruction": 200,
},
)
client.create_index(
collection_name="tech_articles",
index_params=index_params,
)
Index metric compatibility
Use the following tables to choose an index type and metric type for a StructArray vector subfield. Start from the target, then choose the metric family by search mode.
Choose a Zilliz Cloud index type and metric type from the following compatibility tables.
EmbeddingList search
EmbeddingList search uses MAX_SIM* metrics. It treats the vectors in a StructArray vector subfield as an embedding list and returns entity-level results.
| Vector subfield data type | Index type | Metric type |
|---|---|---|
FLOAT_VECTOR, FLOAT16_VECTOR, BFLOAT16_VECTOR, INT8_VECTOR | AUTOINDEX | MAX_SIM, MAX_SIM_COSINE, MAX_SIM_IP, MAX_SIM_L2 |
BINARY_VECTOR | AUTOINDEX | MAX_SIM_HAMMING, MAX_SIM_JACCARD |
Element-level search
Element-level search uses regular vector metrics. It searches each Struct element independently and can return the matched element offset.
| Vector subfield data type | Index type | Metric type |
|---|---|---|
FLOAT_VECTOR, FLOAT16_VECTOR, BFLOAT16_VECTOR, INT8_VECTOR | AUTOINDEX | L2, IP, COSINE |
BINARY_VECTOR | AUTOINDEX | HAMMING, JACCARD |
For version-specific support and other limits, see StructArray Limits.
Verify indexes
After creating indexes, describe the collection or list indexes to confirm that the expected subfield paths are indexed.
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
indexes = client.list_indexes(
collection_name="tech_articles",
)
print(indexes)
import io.milvus.v2.service.index.request.ListIndexesReq;
import java.util.List;
List<String> indexes = client.listIndexes(ListIndexesReq.builder()
.collectionName("tech_articles")
.build());
System.out.println(indexes);
import (
"fmt"
"github.com/milvus-io/milvus/client/v3/milvusclient"
)
indexes, err := cli.ListIndexes(ctx, milvusclient.NewListIndexOption("tech_articles"))
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(indexes)
use milvus::v2::prelude::*;
let resp = client.list_indexes(ListIndexesRequest::builder()
.collection_name("tech_articles").build()?).await?;
println!("{:?}", resp.index_names());
#include <stdexcept>
#include <utility>
#include <iostream>
#include "milvus/MilvusClientV2.h"
milvus::ListIndexesResponse list_resp;
status = client->ListIndexes(milvus::ListIndexesRequest()
.WithCollectionName("tech_articles"),
list_resp);
if (!status.IsOk()) {
throw std::runtime_error(status.Message());
}
for (const auto& name : list_resp.IndexNames()) {
std::cout << name << std::endl;
}
const indexes = await client.listIndexes({
collection_name: "tech_articles",
});
console.log(indexes);
using Milvus.Client.V2.Requests.Index;
var indexes = await client.ListIndexesAsync(new ListIndexesReq
{
CollectionName = "tech_articles"
});
Console.WriteLine(string.Join(", ", indexes.IndexNames));
curl --request POST \
--url "YOUR_CLUSTER_ENDPOINT/v2/vectordb/indexes/list" \
--header "Authorization: Bearer YOUR_CLUSTER_TOKEN" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "tech_articles"
}'
After creating both the vector and scalar indexes above, the list response should contain the following names, in any order. The formatting depends on the SDK:
chunks_emb_list_max_sim
chunks_emb_cosine
chunks_section_inverted
chunks_has_code_inverted
chunks_quality_score_sort
chunks_page_sort
Describe the chunks_emb_cosine index created above to inspect its target field and configuration. The response structure and printed representation differ between SDKs.
- Python
- Java
- Go
- Rust
- C++
- NodeJS
- CSharp
- cURL
index = client.describe_index(
collection_name="tech_articles",
index_name="chunks_emb_cosine",
)
print(index)
import io.milvus.v2.service.index.request.DescribeIndexReq;
import io.milvus.v2.service.index.response.DescribeIndexResp;
DescribeIndexResp index = client.describeIndex(DescribeIndexReq.builder()
.collectionName("tech_articles")
.indexName("chunks_emb_cosine")
.build());
System.out.println(index);
import (
"fmt"
"github.com/milvus-io/milvus/client/v3/milvusclient"
)
indexDesc, err := cli.DescribeIndex(ctx, milvusclient.NewDescribeIndexOption("tech_articles", "chunks_emb_cosine"))
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(indexDesc.IndexType())
use milvus::v2::prelude::*;
let resp = client.describe_index(DescribeIndexRequest::builder()
.collection_name("tech_articles").index_name("chunks_emb_cosine").build()?).await?;
for description in resp.indexes() {
println!("{:?}", description);
}
#include <stdexcept>
#include <utility>
#include <iostream>
#include "milvus/MilvusClientV2.h"
milvus::DescribeIndexResponse desc_resp;
status = client->DescribeIndex(milvus::DescribeIndexRequest()
.WithCollectionName("tech_articles")
.WithIndexName("chunks_emb_cosine"),
desc_resp);
if (!status.IsOk()) {
throw std::runtime_error(status.Message());
}
for (const auto& desc : desc_resp.Descs()) {
std::cout << desc.FieldName() << ": " << desc.IndexName() << std::endl;
}
const index = await client.describeIndex({
collection_name: "tech_articles",
index_name: "chunks_emb_cosine",
});
console.log(index);
using Milvus.Client.V2.Requests.Index;
var index = await client.DescribeIndexAsync(new DescribeIndexReq
{
CollectionName = "tech_articles",
IndexName = "chunks_emb_cosine"
});
foreach (var description in index.Indexes)
{
Console.WriteLine($"{description.FieldName}: {description.IndexName}");
}
curl --request POST \
--url "YOUR_CLUSTER_ENDPOINT/v2/vectordb/indexes/describe" \
--header "Authorization: Bearer YOUR_CLUSTER_TOKEN" \
--header "Content-Type: application/json" \
-d '{
"collectionName": "tech_articles",
"indexName": "chunks_emb_cosine"
}'
The list response contains the index names; the describe response identifies chunks[emb] and the index configuration. Inspect the response or status for errors before using it.
Index rules
| Rule | Explanation |
|---|---|
| Use path syntax for subfield indexes. | Index chunks[emb], not emb or chunks.emb. |
| One vector subfield accepts one index. | Use separate vector subfields if you need different metric families. |
Use MAX_SIM* metrics for EmbeddingList search. | EmbeddingList query data requires an index built with a MAX_SIM* metric. |
| Use regular vector metrics for element-level search. | Element-level search uses regular vector query data and metrics such as COSINE, IP, or L2. |
| Index scalar subfields that appear in filters. | Use scalar index types supported by your target. Element-nullable subfields and scalar ARRAY subfields cannot be indexed. |
| Use element-level metrics on element-nullable vector subfields. | An element-nullable vector subfield (nullable=True), including any vector subfield added to an existing StructArray field, rejects MAX_SIM* metrics. |
| Keep vector-field limits in mind. | The total number of vector fields and vector subfields is limited. See StructArray Limits before adding many vector subfields. |
Common mistakes
-
Creating an index on
chunks.embinstead ofchunks[emb]. -
Creating only a
MAX_SIM*index and then trying to run element-level search on the same subfield. -
Creating only a regular vector index and then trying to run EmbeddingList search on the same subfield.
-
Reusing one vector subfield for both
MAX_SIM*and regular vector metrics. -
Forgetting scalar indexes for heavily used StructArray filters.
-
Indexing a StructArray subfield that does not exist in the Struct schema.
Next steps
-
To run entity-level EmbeddingList search or element-level vector search, read Basic Vector Search with StructArray.
-
To filter StructArray scalar subfields during search, read Filtered Search with StructArray.
-
To review index and metric limits, read StructArray Limits.