tencent cloud

Elasticsearch Service

Data Writing

Download
포커스 모드
폰트 크기
마지막 업데이트 시간: 2026-08-12 18:13:52
AI 번역
This document describes the key points of vector data writing. For more details, refer to the related document.
ES provides multiple flexible methods for writing vector data into the system, whether you have precomputed vectors or need to generate vectors in real time during the write process. This document describes the different writing methods in detail.

Method 1: Directly Writing Precomputed Vectors

If you already have precomputed vectors (for example, generated by an external Python script or a model service), you can directly write these vectors.
//Write a single document.
PUT /book-index/_doc/1
{
"id": "1001",
"category": "Fiction",
"price":10,
"title_text": "One Hundred Years of Solitude",
"title_vector": [0.1, 0.2, 0.3 ...],
"content_text": "The rise and fall of the town of Macondo and the legendary stories of the Buendía family",
"content_vector": [0.5, 0.6, 0.7, ... ]
}

//Perform bulk write.
POST /_bulk
{ "index": { "_index": "book-index", "_id": "2" } }
{ "id": "1002", "category": "History", "price": 20, "title_text": "Sapiens: A Brief History of Humankind", "title_vector": [0.1, 0.2, 0.3 ...], "content_text": "The developmental history of humanity from the Cognitive Revolution to the Scientific Revolution", "content_vector": [0.1, 0.2, 0.3, ...]}
{ "index": { "_index": "book-index", "_id": "3" } }
{ "id": "1003", "category": "Science Fiction", "price": 30, "title_text": "The Three-Body Problem", "title_vector": [0.8, 0.7, 0.6 ...], "content_text": "Human civilization and the laws of cosmic sociology", "content_vector": [0.1, 0.2, 0.3, ...]}


Method 2: Automatically Generating Vectors Through Ingest Pipeline

1. Creating an Ingest Pipeline
Based on the text embedding model inference service created earlier, you can create an ingest pipeline to perform embedding processing during the write process:
PUT /_ingest/pipeline/text-embedding
{
"description": "Text embedding pipeline",
"processors": [
{
"inference": {
"model_id": "bge-base-zh",
"ignore_missing": true, // Ignore missing input fields.
"input_output": [
{
"input_field": "title_text",
"output_field": "title_vector"
},
{
"input_field": "content_text",
"output_field": "content_vector"
}
]
}
}
]
}
Note:
For the model_id value in the ingest pipeline, if the model is deployed through a machine learning node, directly use the value of the model_id parameter from that node; if the model is deployed through an _inference endpoint, use the name of the _inference endpoint. If both are set up, either can be used. They both correspond to inference from the same underlying model. The difference is that the former accesses the model for inference directly, while the latter performs inference through the _inference endpoint.
2. Writing Data
When writing data, you only need to write scalar data. The model inference service in the ingest pipeline will automatically generate vector data.
//Write a single document.
PUT /book-index/_doc/1?pipeline=text-embedding
{
"id": "1001",
"category": "Fiction",
"price":10,
"title_text": "One Hundred Years of Solitude",
"content_text": "The rise and fall of the town of Macondo and the legendary stories of the Buendía family"
}

//Perform bulk write.
POST /_bulk?pipeline=text-embedding
{ "index": { "_index": "book-index", "_id": "2" } }
{ "id": "1002", "category": "History", "price": 20, "title_text": "Sapiens: A Brief History of Humankind", "content_text": "The developmental history of humanity from the Cognitive Revolution to the Scientific Revolution"}
{ "index": { "_index": "book-index", "_id": "3" } }
{ "id": "1003", "category": "Science Fiction", "price": 30, "title_text": "The Three-Body Problem", "content_text": "Human civilization and the laws of cosmic sociology"}
Check the write results through GET /book-index/_search. The vectors have been automatically generated.

도움말 및 지원

문제 해결에 도움이 되었나요?

피드백