[[feature-vector]]
=== Feature vector datatype

A `feature_vector` field can index numeric feature vectors, so that they can
later be used to boost documents in queries with a
<<query-dsl-feature-query,`feature`>> query.

It is analogous to the <<feature,`feature`>> datatype but is better suited
when the list of features is sparse so that it wouldn't be reasonable to add
one field to the mappings for each of them.

[source,js]
--------------------------------------------------
PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "topics": {
          "type": "feature_vector" <1>
        }
      }
    }
  }
}

PUT my_index/_doc/1
{
  "topics": { <2>
    "politics": 20,
    "economics": 50.8
  }
}

PUT my_index/_doc/2
{
  "topics": {
    "politics": 5.2,
    "sports": 80.1
  }
}

GET my_index/_search
{
  "query": {
    "feature": {
      "field": "topics.politics"
    }
  }
}
--------------------------------------------------
// CONSOLE
<1> Feature vector fields must use the `feature_vector` field type
<2> Feature vector fields must be a hash with string keys and strictly positive numeric values

NOTE: `feature_vector` fields only support single-valued features and strictly
positive values. Multi-valued fields and zero or negative values will be rejected.

NOTE: `feature_vector` fields do not support sorting or aggregating and may 
only be queried using <<query-dsl-feature-query,`feature`>> queries.

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

