Skip to content

Commit a30ce6a

Browse files
Rename feature, feature_vector and feature_query (#37794)
Ranaming as follows: feature -> rank_feature feature_vector -> rank_features feature query -> rank_feature query Ranaming is done to distinguish from other vector types. Closes #36723
1 parent 9d87ca5 commit a30ce6a

21 files changed

+243
-241
lines changed

docs/reference/mapping/types.asciidoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ string:: <<text,`text`>> and <<keyword,`keyword`>>
4343

4444
<<alias>>:: Defines an alias to an existing field.
4545

46-
<<feature>>:: Record numeric features to boost hits at query time.
46+
<<rank-feature>>:: Record numeric feature to boost hits at query time.
4747

48-
<<feature-vector>>:: Record numeric feature vectors to boost hits at query time.
48+
<<rank-features>>:: Record numeric features to boost hits at query time.
4949

5050
<<dense-vector>>:: Record dense vectors of float values.
5151

@@ -100,9 +100,9 @@ include::types/percolator.asciidoc[]
100100

101101
include::types/parent-join.asciidoc[]
102102

103-
include::types/feature.asciidoc[]
103+
include::types/rank-feature.asciidoc[]
104104

105-
include::types/feature-vector.asciidoc[]
105+
include::types/rank-features.asciidoc[]
106106

107107
include::types/dense-vector.asciidoc[]
108108

docs/reference/mapping/types/feature.asciidoc

Lines changed: 0 additions & 57 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
[[rank-feature]]
2+
=== Rank feature datatype
3+
4+
A `rank_feature` field can index numbers so that they can later be used to boost
5+
documents in queries with a <<query-dsl-rank-feature-query,`rank_feature`>> query.
6+
7+
[source,js]
8+
--------------------------------------------------
9+
PUT my_index
10+
{
11+
"mappings": {
12+
"properties": {
13+
"pagerank": {
14+
"type": "rank_feature" <1>
15+
},
16+
"url_length": {
17+
"type": "rank_feature",
18+
"positive_score_impact": false <2>
19+
}
20+
}
21+
}
22+
}
23+
24+
PUT my_index/_doc/1
25+
{
26+
"pagerank": 8,
27+
"url_length": 22
28+
}
29+
30+
GET my_index/_search
31+
{
32+
"query": {
33+
"rank_feature": {
34+
"field": "pagerank"
35+
}
36+
}
37+
}
38+
--------------------------------------------------
39+
// CONSOLE
40+
<1> Rank feature fields must use the `rank_feature` field type
41+
<2> Rank features that correlate negatively with the score need to declare it
42+
43+
NOTE: `rank_feature` fields only support single-valued fields and strictly positive
44+
values. Multi-valued fields and negative values will be rejected.
45+
46+
NOTE: `rank_feature` fields do not support querying, sorting or aggregating. They may
47+
only be used within <<query-dsl-rank-feature-query,`rank_feature`>> queries.
48+
49+
NOTE: `rank_feature` fields only preserve 9 significant bits for the precision, which
50+
translates to a relative error of about 0.4%.
51+
52+
Rank features that correlate negatively with the score should set
53+
`positive_score_impact` to `false` (defaults to `true`). This will be used by
54+
the <<query-dsl-rank-feature-query,`rank_feature`>> query to modify the scoring formula
55+
in such a way that the score decreases with the value of the feature instead of
56+
increasing. For instance in web search, the url length is a commonly used
57+
feature which correlates negatively with scores.

docs/reference/mapping/types/feature-vector.asciidoc renamed to docs/reference/mapping/types/rank-features.asciidoc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
[[feature-vector]]
2-
=== Feature vector datatype
1+
[[rank-features]]
2+
=== Rank features datatype
33

4-
A `feature_vector` field can index numeric feature vectors, so that they can
4+
A `rank_features` field can index numeric feature vectors, so that they can
55
later be used to boost documents in queries with a
6-
<<query-dsl-feature-query,`feature`>> query.
6+
<<query-dsl-rank-feature-query,`rank_feature`>> query.
77

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

@@ -16,7 +16,7 @@ PUT my_index
1616
"mappings": {
1717
"properties": {
1818
"topics": {
19-
"type": "feature_vector" <1>
19+
"type": "rank_features" <1>
2020
}
2121
}
2222
}
@@ -41,22 +41,22 @@ PUT my_index/_doc/2
4141
GET my_index/_search
4242
{
4343
"query": {
44-
"feature": {
44+
"rank_feature": {
4545
"field": "topics.politics"
4646
}
4747
}
4848
}
4949
--------------------------------------------------
5050
// CONSOLE
51-
<1> Feature vector fields must use the `feature_vector` field type
52-
<2> Feature vector fields must be a hash with string keys and strictly positive numeric values
51+
<1> Rank features fields must use the `rank_features` field type
52+
<2> Rank features fields must be a hash with string keys and strictly positive numeric values
5353

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

57-
NOTE: `feature_vector` fields do not support sorting or aggregating and may
58-
only be queried using <<query-dsl-feature-query,`feature`>> queries.
57+
NOTE: `rank_features` fields do not support sorting or aggregating and may
58+
only be queried using <<query-dsl-rank-feature-query,`rank_feature`>> queries.
5959

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

docs/reference/query-dsl/feature-query.asciidoc renamed to docs/reference/query-dsl/rank-feature-query.asciidoc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
[[query-dsl-feature-query]]
2-
=== Feature Query
1+
[[query-dsl-rank-feature-query]]
2+
=== Rank Feature Query
33

4-
The `feature` query is a specialized query that only works on
5-
<<feature,`feature`>> fields and <<feature-vector,`feature_vector`>> fields.
4+
The `rank_feature` query is a specialized query that only works on
5+
<<rank-feature,`rank_feature`>> fields and <<rank-features,`rank_features`>> fields.
66
Its goal is to boost the score of documents based on the values of numeric
77
features. It is typically put in a `should` clause of a
88
<<query-dsl-bool-query,`bool`>> query so that its score is added to the score
@@ -32,14 +32,14 @@ PUT test
3232
"mappings": {
3333
"properties": {
3434
"pagerank": {
35-
"type": "feature"
35+
"type": "rank_feature"
3636
},
3737
"url_length": {
38-
"type": "feature",
38+
"type": "rank_feature",
3939
"positive_score_impact": false
4040
},
4141
"topics": {
42-
"type": "feature_vector"
42+
"type": "rank_features"
4343
}
4444
}
4545
}
@@ -97,18 +97,18 @@ GET test/_search
9797
],
9898
"should": [
9999
{
100-
"feature": {
100+
"rank_feature": {
101101
"field": "pagerank"
102102
}
103103
},
104104
{
105-
"feature": {
105+
"rank_feature": {
106106
"field": "url_length",
107107
"boost": 0.1
108108
}
109109
},
110110
{
111-
"feature": {
111+
"rank_feature": {
112112
"field": "topics.sports",
113113
"boost": 0.4
114114
}
@@ -123,28 +123,28 @@ GET test/_search
123123
[float]
124124
=== Supported functions
125125

126-
The `feature` query supports 3 functions in order to boost scores using the
127-
values of features. If you do not know where to start, we recommend that you
126+
The `rank_feature` query supports 3 functions in order to boost scores using the
127+
values of rank features. If you do not know where to start, we recommend that you
128128
start with the `saturation` function, which is the default when no function is
129129
provided.
130130

131131
[float]
132132
==== Saturation
133133

134134
This function gives a score that is equal to `S / (S + pivot)` where `S` is the
135-
value of the feature and `pivot` is a configurable pivot value so that the
135+
value of the rank feature and `pivot` is a configurable pivot value so that the
136136
result will be less than +0.5+ if `S` is less than pivot and greater than +0.5+
137137
otherwise. Scores are always is +(0, 1)+.
138138

139-
If the feature has a negative score impact then the function will be computed as
139+
If the rank feature has a negative score impact then the function will be computed as
140140
`pivot / (S + pivot)`, which decreases when `S` increases.
141141

142142
[source,js]
143143
--------------------------------------------------
144144
GET test/_search
145145
{
146146
"query": {
147-
"feature": {
147+
"rank_feature": {
148148
"field": "pagerank",
149149
"saturation": {
150150
"pivot": 8
@@ -166,7 +166,7 @@ train a good pivot value.
166166
GET test/_search
167167
{
168168
"query": {
169-
"feature": {
169+
"rank_feature": {
170170
"field": "pagerank",
171171
"saturation": {}
172172
}
@@ -180,17 +180,17 @@ GET test/_search
180180
==== Logarithm
181181

182182
This function gives a score that is equal to `log(scaling_factor + S)` where
183-
`S` is the value of the feature and `scaling_factor` is a configurable scaling
183+
`S` is the value of the rank feature and `scaling_factor` is a configurable scaling
184184
factor. Scores are unbounded.
185185

186-
This function only supports features that have a positive score impact.
186+
This function only supports rank features that have a positive score impact.
187187

188188
[source,js]
189189
--------------------------------------------------
190190
GET test/_search
191191
{
192192
"query": {
193-
"feature": {
193+
"rank_feature": {
194194
"field": "pagerank",
195195
"log": {
196196
"scaling_factor": 4
@@ -219,7 +219,7 @@ that you stick to the `saturation` function instead.
219219
GET test/_search
220220
{
221221
"query": {
222-
"feature": {
222+
"rank_feature": {
223223
"field": "pagerank",
224224
"sigmoid": {
225225
"pivot": 7,

docs/reference/query-dsl/script-score-query.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ There are faster alternative query types that can efficiently skip
211211
non-competitive hits:
212212

213213
* If you want to boost documents on some static fields, use
214-
<<query-dsl-feature-query, Feature Query>>.
214+
<<query-dsl-rank-feature-query, Rank Feature Query>>.
215215

216216

217217
==== Transition from Function Score Query

docs/reference/query-dsl/special-queries.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ A query that allows to modify the score of a sub-query with a script.
2323
This query finds queries that are stored as documents that match with
2424
the specified document.
2525

26-
<<query-dsl-feature-query,`feature` query>>::
26+
<<query-dsl-rank-feature-query,`rank_feature` query>>::
2727

2828
A query that computes scores based on the values of numeric features and is
2929
able to efficiently skip non-competitive hits.
@@ -40,6 +40,6 @@ include::script-score-query.asciidoc[]
4040

4141
include::percolate-query.asciidoc[]
4242

43-
include::feature-query.asciidoc[]
43+
include::rank-feature-query.asciidoc[]
4444

4545
include::wrapper-query.asciidoc[]

modules/mapper-extras/src/main/java/org/elasticsearch/index/mapper/MapperExtrasPlugin.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
package org.elasticsearch.index.mapper;
2121

2222
import org.elasticsearch.index.mapper.MetadataFieldMapper.TypeParser;
23-
import org.elasticsearch.index.query.FeatureQueryBuilder;
23+
import org.elasticsearch.index.query.RankFeatureQueryBuilder;
2424
import org.elasticsearch.plugins.MapperPlugin;
2525
import org.elasticsearch.plugins.Plugin;
2626
import org.elasticsearch.plugins.SearchPlugin;
@@ -37,22 +37,23 @@ public Map<String, Mapper.TypeParser> getMappers() {
3737
Map<String, Mapper.TypeParser> mappers = new LinkedHashMap<>();
3838
mappers.put(ScaledFloatFieldMapper.CONTENT_TYPE, new ScaledFloatFieldMapper.TypeParser());
3939
mappers.put(TokenCountFieldMapper.CONTENT_TYPE, new TokenCountFieldMapper.TypeParser());
40-
mappers.put(FeatureFieldMapper.CONTENT_TYPE, new FeatureFieldMapper.TypeParser());
41-
mappers.put(FeatureVectorFieldMapper.CONTENT_TYPE, new FeatureVectorFieldMapper.TypeParser());
40+
mappers.put(RankFeatureFieldMapper.CONTENT_TYPE, new RankFeatureFieldMapper.TypeParser());
41+
mappers.put(RankFeaturesFieldMapper.CONTENT_TYPE, new RankFeaturesFieldMapper.TypeParser());
4242
mappers.put(DenseVectorFieldMapper.CONTENT_TYPE, new DenseVectorFieldMapper.TypeParser());
4343
mappers.put(SparseVectorFieldMapper.CONTENT_TYPE, new SparseVectorFieldMapper.TypeParser());
4444
return Collections.unmodifiableMap(mappers);
4545
}
4646

4747
@Override
4848
public Map<String, TypeParser> getMetadataMappers() {
49-
return Collections.singletonMap(FeatureMetaFieldMapper.CONTENT_TYPE, new FeatureMetaFieldMapper.TypeParser());
49+
return Collections.singletonMap(RankFeatureMetaFieldMapper.CONTENT_TYPE, new RankFeatureMetaFieldMapper.TypeParser());
5050
}
5151

5252
@Override
5353
public List<QuerySpec<?>> getQueries() {
5454
return Collections.singletonList(
55-
new QuerySpec<>(FeatureQueryBuilder.NAME, FeatureQueryBuilder::new, p -> FeatureQueryBuilder.PARSER.parse(p, null)));
55+
new QuerySpec<>(RankFeatureQueryBuilder.NAME, RankFeatureQueryBuilder::new,
56+
p -> RankFeatureQueryBuilder.PARSER.parse(p, null)));
5657
}
5758

5859
}

0 commit comments

Comments
 (0)