tencent cloud

Elasticsearch Service

DocumentationElasticsearch ServiceVector Search GuideSpecial Note on Flexibly Supporting a Variable Number of Vectors in a Single Field

Special Note on Flexibly Supporting a Variable Number of Vectors in a Single Field

Download
Focus Mode
Font Size
Last updated: 2026-08-12 18:13:52
AI-Translated
This document introduces the key points of nested search. You can refer to the related document for more details.
ES allows a single field to support a vector array through nested, with a variable number of vectors. This feature is very useful. Let us look at a video search example.

Example Background

Suppose you need to perform vector search on videos. The challenge is that each video has a different number of extracted frames. You can solve this using nested fields.
Example: A video record has id, title, content, and image fields, where image stores the vector data of frames extracted from the video. Each video has n images, and n is not fixed.

Creating an Index

Specify image as a nested field when the mappings are created:
// id, title, and content are text fields.
// num in image is the image number, such as the frame number (optional).
// emb in image is the image embedding data; image = [image1_emb, image2_emb, image3_emb, ..., imagen_emb].

PUT /image_embeddings
{
"mappings": {
"properties": {
"id": {
"type": "keyword"
},
"title": {
"type": "text"
},
"content": {
"type": "text"
},
"image": {
"type": "nested",
"properties": {
"num": {"type": "keyword"},
"emb": {
"type": "dense_vector",
"dims": 5,
"index_options": {
"type": "int8_hnsw"
},
"similarity": "cosine"
}
}
}
}
}
}

Writing Data

Wrap multiple vector groups in an array format, as shown below:
POST /image_embeddings/_doc/1
{
"id": "book_001",
"title": "Sunny day",
"content": "On this windy day, I tried to hold your hand",
"image": [
{"num": "0", "emb": [0.1,0.2,0.3,0.4,0.5]},
{"num": "1", "emb": [0.6,0.7,0.8,0.9,1.0]},
{"num": "2", "emb": [0.2,0.3,0.4,0.5,0.6]}
]
}

POST /image_embeddings/_doc/2
{
"id": "book_002",
"title": "Heading north",
"content": "Heading north, I tried to hold your hand",
"image": [
{"num": "0", "emb": [0.1,0.2,0.3,0.4,0.5]},
{"num": "1", "emb": [0.6,0.7,0.8,0.9,1.0]}
]
}

POST /image_embeddings/_doc/3
{
"id": "book_003",
"title": " Nunchaku",
"content": "Heng Heng Ha Hei",
"image": [
{"num": "0", "emb": [0.1,0.2,0.3,0.4,0.5]},
{"num": "1", "emb": [0.6,0.7,0.8,0.9,1.0]},
{"num": "2", "emb": [0.1,0.2,0.3,0.4,0.5]},
{"num": "3", "emb": [0.6,0.7,0.8,0.9,1.0]},
{"num": "4", "emb": [0.1,0.2,0.3,0.4,0.5]},
{"num": "5", "emb": [0.6,0.7,0.8,0.9,1.0]}
]
}

Performing Vector Search

Query data. The syntax is the same as the hybrid search described earlier. The score of a nested field uses max as the final score.
GET book-index/_search
{
"retriever": {
"rrf": {
"retrievers": [
{
"retriever": {
"knn": {
"field": "image.emb",
"query_vector": [0.1, 0.2, 0.3,0.4,0.5],
"k": 5,
"num_candidates": 50
}
},
"weight": 0.8
},
{
"retriever": {
"standard": {
"query": {
"match": {
"title": "Sunny day"
}
}
}
},
"weight": 0.2
}
],
"rank_window_size": 50,
"rank_constant": 20
}
}
}

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback