Skip to content

Commit c271026

Browse files
committed
[7.x] Add RankFeatures field
1 parent bd7a0d9 commit c271026

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

elasticsearch_dsl/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
Percolator,
6767
RangeField,
6868
RankFeature,
69+
RankFeatures,
6970
ScaledFloat,
7071
SearchAsYouType,
7172
Short,
@@ -139,6 +140,7 @@
139140
"RangeFacet",
140141
"RangeField",
141142
"RankFeature",
143+
"RankFeatures",
142144
"SF",
143145
"ScaledFloat",
144146
"Search",

elasticsearch_dsl/field.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,10 @@ class RankFeature(Float):
378378
name = "rank_feature"
379379

380380

381+
class RankFeatures(Field):
382+
name = "rank_features"
383+
384+
381385
class Integer(Field):
382386
name = "integer"
383387
_coerce = True

tests/test_field.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ def test_constant_keyword():
177177
assert f.to_dict() == {"type": "constant_keyword"}
178178

179179

180+
def test_rank_features():
181+
f = field.RankFeatures()
182+
assert f.to_dict() == {"type": "rank_features"}
183+
184+
180185
def test_object_dynamic_values():
181186
for dynamic in True, False, "strict":
182187
f = field.Object(dynamic=dynamic)

tests/test_integration/test_document.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
Nested,
3838
Object,
3939
Q,
40+
RankFeatures,
4041
Text,
4142
analyzer,
4243
)
@@ -52,6 +53,7 @@ class User(InnerDoc):
5253
class Wiki(Document):
5354
owner = Object(User)
5455
views = Long()
56+
ranked = RankFeatures()
5557

5658
class Index:
5759
name = "test-wiki"
@@ -204,7 +206,11 @@ def test_nested_top_hits_are_wrapped_properly(pull_request):
204206

205207
def test_update_object_field(write_client):
206208
Wiki.init()
207-
w = Wiki(owner=User(name="Honza Kral"), _id="elasticsearch-py")
209+
w = Wiki(
210+
owner=User(name="Honza Kral"),
211+
_id="elasticsearch-py",
212+
ranked={"test1": 0.1, "topic2": 0.2},
213+
)
208214
w.save()
209215

210216
assert "updated" == w.update(owner=[{"name": "Honza"}, {"name": "Nick"}])
@@ -215,6 +221,8 @@ def test_update_object_field(write_client):
215221
assert w.owner[0].name == "Honza"
216222
assert w.owner[1].name == "Nick"
217223

224+
assert w.ranked == {"test1": 0.1, "topic2": 0.2}
225+
218226

219227
def test_update_script(write_client):
220228
Wiki.init()

0 commit comments

Comments
 (0)