Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RankFeatures field #1465

Merged
merged 2 commits into from
Dec 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions elasticsearch_dsl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
Percolator,
RangeField,
RankFeature,
RankFeatures,
ScaledFloat,
SearchAsYouType,
Short,
Expand Down Expand Up @@ -139,6 +140,7 @@
"RangeFacet",
"RangeField",
"RankFeature",
"RankFeatures",
"SF",
"ScaledFloat",
"Search",
Expand Down
4 changes: 4 additions & 0 deletions elasticsearch_dsl/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ class RankFeature(Float):
name = "rank_feature"


class RankFeatures(Field):
name = "rank_features"


class Integer(Field):
name = "integer"
_coerce = True
Expand Down
5 changes: 5 additions & 0 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def test_constant_keyword():
assert f.to_dict() == {"type": "constant_keyword"}


def test_rank_features():
f = field.RankFeatures()
assert f.to_dict() == {"type": "rank_features"}


def test_object_dynamic_values():
for dynamic in True, False, "strict":
f = field.Object(dynamic=dynamic)
Expand Down
10 changes: 9 additions & 1 deletion tests/test_integration/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
Nested,
Object,
Q,
RankFeatures,
Text,
analyzer,
)
Expand All @@ -52,6 +53,7 @@ class User(InnerDoc):
class Wiki(Document):
owner = Object(User)
views = Long()
ranked = RankFeatures()

class Index:
name = "test-wiki"
Expand Down Expand Up @@ -204,7 +206,11 @@ def test_nested_top_hits_are_wrapped_properly(pull_request):

def test_update_object_field(write_client):
Wiki.init()
w = Wiki(owner=User(name="Honza Kral"), _id="elasticsearch-py")
w = Wiki(
owner=User(name="Honza Kral"),
_id="elasticsearch-py",
ranked={"test1": 0.1, "topic2": 0.2},
)
w.save()

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

assert w.ranked == {"test1": 0.1, "topic2": 0.2}


def test_update_script(write_client):
Wiki.init()
Expand Down