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

Update ScriptFilter #191

Merged
merged 1 commit into from
Apr 21, 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: 1 addition & 1 deletion eland/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def __init__(self, field):
class ScriptFilter(BooleanFilter):
def __init__(self, inline, lang=None, params=None):
super().__init__()
script = {"inline": inline}
script = {"source": inline}
if lang is not None:
script["lang"] = lang
if params is not None:
Expand Down
12 changes: 6 additions & 6 deletions eland/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def __gt__(self, other):
if isinstance(other, Series):
# Need to use scripted query to compare to values
painless = f"doc['{self.name}'].value > doc['{other.name}'].value"
return ScriptFilter(painless)
return ScriptFilter(painless, lang="painless")
elif isinstance(other, (int, float)):
return Greater(field=self.name, value=other)
else:
Expand All @@ -419,7 +419,7 @@ def __lt__(self, other):
if isinstance(other, Series):
# Need to use scripted query to compare to values
painless = f"doc['{self.name}'].value < doc['{other.name}'].value"
return ScriptFilter(painless)
return ScriptFilter(painless, lang="painless")
elif isinstance(other, (int, float)):
return Less(field=self.name, value=other)
else:
Expand All @@ -429,7 +429,7 @@ def __ge__(self, other):
if isinstance(other, Series):
# Need to use scripted query to compare to values
painless = f"doc['{self.name}'].value >= doc['{other.name}'].value"
return ScriptFilter(painless)
return ScriptFilter(painless, lang="painless")
elif isinstance(other, (int, float)):
return GreaterEqual(field=self.name, value=other)
else:
Expand All @@ -439,7 +439,7 @@ def __le__(self, other):
if isinstance(other, Series):
# Need to use scripted query to compare to values
painless = f"doc['{self.name}'].value <= doc['{other.name}'].value"
return ScriptFilter(painless)
return ScriptFilter(painless, lang="painless")
elif isinstance(other, (int, float)):
return LessEqual(field=self.name, value=other)
else:
Expand All @@ -449,7 +449,7 @@ def __eq__(self, other):
if isinstance(other, Series):
# Need to use scripted query to compare to values
painless = f"doc['{self.name}'].value == doc['{other.name}'].value"
return ScriptFilter(painless)
return ScriptFilter(painless, lang="painless")
elif isinstance(other, (int, float)):
return Equal(field=self.name, value=other)
elif isinstance(other, str):
Expand All @@ -461,7 +461,7 @@ def __ne__(self, other):
if isinstance(other, Series):
# Need to use scripted query to compare to values
painless = f"doc['{self.name}'].value != doc['{other.name}'].value"
return ScriptFilter(painless)
return ScriptFilter(painless, lang="painless")
elif isinstance(other, (int, float)):
return NotFilter(Equal(field=self.name, value=other))
elif isinstance(other, str):
Expand Down
5 changes: 3 additions & 2 deletions eland/tests/operators/test_operators_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ def test_leaf_boolean_filter(self):
assert IsNull("a").build() == {"missing": {"field": "a"}}
assert NotNull("a").build() == {"exists": {"field": "a"}}
assert ScriptFilter(
'doc["num1"].value > params.param1', params={"param1": 5}
'doc["num1"].value > params.param1', lang="painless", params={"param1": 5}
).build() == {
"script": {
"script": {
"inline": 'doc["num1"].value > params.param1',
"lang": "painless",
"source": 'doc["num1"].value > params.param1',
"params": {"param1": 5},
}
}
Expand Down