From 9228de099f06f7428aa1d4e1fef5b2552e58044a Mon Sep 17 00:00:00 2001 From: Daniel Mesejo Date: Mon, 20 Apr 2020 23:54:33 +0200 Subject: [PATCH] change ScriptFilter to source, add painless explicitly, update test --- eland/filter.py | 2 +- eland/series.py | 12 ++++++------ eland/tests/operators/test_operators_pytest.py | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/eland/filter.py b/eland/filter.py index f6d45f90..cf0387bf 100644 --- a/eland/filter.py +++ b/eland/filter.py @@ -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: diff --git a/eland/series.py b/eland/series.py index 2cfaeac6..e31b54b2 100644 --- a/eland/series.py +++ b/eland/series.py @@ -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: @@ -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: @@ -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: @@ -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: @@ -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): @@ -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): diff --git a/eland/tests/operators/test_operators_pytest.py b/eland/tests/operators/test_operators_pytest.py index 495d7222..cf65821a 100644 --- a/eland/tests/operators/test_operators_pytest.py +++ b/eland/tests/operators/test_operators_pytest.py @@ -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}, } }