[[feature]]
=== Feature datatype

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

[source,js]
--------------------------------------------------
PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "pagerank": {
          "type": "feature" <1>
        },
        "url_length": {
          "type": "feature",
          "positive_score_impact": false <2>
        }
      }
    }
  }
}

PUT my_index/_doc/1
{
  "pagerank": 8,
  "url_length": 22
}

GET my_index/_search
{
  "query": {
    "feature": {
      "field": "pagerank"
    }
  }
}
--------------------------------------------------
// CONSOLE
<1> Feature fields must use the `feature` field type
<2> Features that correlate negatively with the score need to declare it

NOTE: `feature` fields only support single-valued fields and strictly positive
values. Multi-valued fields and negative values will be rejected.

NOTE: `feature` fields do not support querying, sorting or aggregating. They may
only be used within <<query-dsl-feature-query,`feature`>> queries.

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

Features that correlate negatively with the score should set
`positive_score_impact` to `false` (defaults to `true`). This will be used by
the <<query-dsl-feature-query,`feature`>> query to modify the scoring formula
in such a way that the score decreases with the value of the feature instead of
increasing. For instance in web search, the url length is a commonly used
feature which correlates negatively with scores.
