mirror of
https://github.com/elastic/eland.git
synced 2025-07-11 00:02:14 +08:00
Change ScriptFilter from inline to source for script caching
This commit is contained in:
parent
a779f04a6d
commit
fe6589ae6a
@ -171,7 +171,7 @@ class NotNull(BooleanFilter):
|
||||
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:
|
||||
|
@ -409,7 +409,7 @@ class Series(NDFrame):
|
||||
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 @@ class Series(NDFrame):
|
||||
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 @@ class Series(NDFrame):
|
||||
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 @@ class Series(NDFrame):
|
||||
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 @@ class Series(NDFrame):
|
||||
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 @@ class Series(NDFrame):
|
||||
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):
|
||||
|
@ -44,11 +44,12 @@ class TestOperators:
|
||||
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},
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user