Recently, I was working on migrating our Elasticsearch cluster to serverless. We have an index where some field stores dense vectors used in KNN search.
When I search the index, I do not see any vector shown in the document source.
PUT my-index
{
"mappings": {
"properties": {
"my_vector": {
"type": "dense_vector",
"dims": 3
},
"my_text": {
"type": "keyword"
}
}
}
}
PUT my-index/_doc/1
{
"my_text" : "text1",
"my_vector" : [0.5, 10, 6]
}
PUT my-index/_doc/2
{
"my_text" : "text2",
"my_vector" : [-0.5, 10, 10]
}
GET my-index/_searchFor each hit, you only see something like this:
{
"_index": "my-index",
"_id": "1",
"_score": 1,
"_source": {
"my_text": "text1"
}It turns out this is intended by Elasticsearch to reduce the storage cost. For serverless and Elastic 9.2, the vector field is intentionally omitted to save storage, as explained in this blog post.
To show the vector field, you need to provide additional parameter to search api:
GET my-index/_search
{
"_source": {
"exclude_vectors": false
}
}There is also an index setting to control this behaviour:
{"index.mapping.exclude_source_vectors": false}This is also explained the dense_vector doc.