Sparse vector field type

edit

A sparse_vector field can index features and weights so that they can later be used to query documents in queries with a text_expansion query.

sparse_vector is the field type that should be used with ELSER mappings.

response = client.indices.create(
  index: 'my-index',
  body: {
    mappings: {
      properties: {
        'text.tokens' => {
          type: 'sparse_vector'
        }
      }
    }
  }
)
puts response
PUT my-index
{
  "mappings": {
    "properties": {
      "text.tokens": {
        "type": "sparse_vector"
      }
    }
  }
}

See semantic search with ELSER for a complete example on adding documents to a sparse_vector mapped field using ELSER.

sparse_vector fields can not be included in indices that were created on Elasticsearch versions between 8.0 and 8.10

sparse_vector fields only support single-valued fields and strictly positive values. Multi-valued fields and negative values will be rejected.

sparse_vector fields do not support querying, sorting or aggregating. They may only be used within text_expansion queries.

sparse_vector fields only preserve 9 significant bits for the precision, which translates to a relative error of about 0.4%.