mirror of
https://github.com/elastic/eland.git
synced 2025-07-24 00:00:39 +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):
|
class ScriptFilter(BooleanFilter):
|
||||||
def __init__(self, inline, lang=None, params=None):
|
def __init__(self, inline, lang=None, params=None):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
script = {"inline": inline}
|
script = {"source": inline}
|
||||||
if lang is not None:
|
if lang is not None:
|
||||||
script["lang"] = lang
|
script["lang"] = lang
|
||||||
if params is not None:
|
if params is not None:
|
||||||
|
@ -409,7 +409,7 @@ class Series(NDFrame):
|
|||||||
if isinstance(other, Series):
|
if isinstance(other, Series):
|
||||||
# Need to use scripted query to compare to values
|
# Need to use scripted query to compare to values
|
||||||
painless = f"doc['{self.name}'].value > doc['{other.name}'].value"
|
painless = f"doc['{self.name}'].value > doc['{other.name}'].value"
|
||||||
return ScriptFilter(painless)
|
return ScriptFilter(painless, lang="painless")
|
||||||
elif isinstance(other, (int, float)):
|
elif isinstance(other, (int, float)):
|
||||||
return Greater(field=self.name, value=other)
|
return Greater(field=self.name, value=other)
|
||||||
else:
|
else:
|
||||||
@ -419,7 +419,7 @@ class Series(NDFrame):
|
|||||||
if isinstance(other, Series):
|
if isinstance(other, Series):
|
||||||
# Need to use scripted query to compare to values
|
# Need to use scripted query to compare to values
|
||||||
painless = f"doc['{self.name}'].value < doc['{other.name}'].value"
|
painless = f"doc['{self.name}'].value < doc['{other.name}'].value"
|
||||||
return ScriptFilter(painless)
|
return ScriptFilter(painless, lang="painless")
|
||||||
elif isinstance(other, (int, float)):
|
elif isinstance(other, (int, float)):
|
||||||
return Less(field=self.name, value=other)
|
return Less(field=self.name, value=other)
|
||||||
else:
|
else:
|
||||||
@ -429,7 +429,7 @@ class Series(NDFrame):
|
|||||||
if isinstance(other, Series):
|
if isinstance(other, Series):
|
||||||
# Need to use scripted query to compare to values
|
# Need to use scripted query to compare to values
|
||||||
painless = f"doc['{self.name}'].value >= doc['{other.name}'].value"
|
painless = f"doc['{self.name}'].value >= doc['{other.name}'].value"
|
||||||
return ScriptFilter(painless)
|
return ScriptFilter(painless, lang="painless")
|
||||||
elif isinstance(other, (int, float)):
|
elif isinstance(other, (int, float)):
|
||||||
return GreaterEqual(field=self.name, value=other)
|
return GreaterEqual(field=self.name, value=other)
|
||||||
else:
|
else:
|
||||||
@ -439,7 +439,7 @@ class Series(NDFrame):
|
|||||||
if isinstance(other, Series):
|
if isinstance(other, Series):
|
||||||
# Need to use scripted query to compare to values
|
# Need to use scripted query to compare to values
|
||||||
painless = f"doc['{self.name}'].value <= doc['{other.name}'].value"
|
painless = f"doc['{self.name}'].value <= doc['{other.name}'].value"
|
||||||
return ScriptFilter(painless)
|
return ScriptFilter(painless, lang="painless")
|
||||||
elif isinstance(other, (int, float)):
|
elif isinstance(other, (int, float)):
|
||||||
return LessEqual(field=self.name, value=other)
|
return LessEqual(field=self.name, value=other)
|
||||||
else:
|
else:
|
||||||
@ -449,7 +449,7 @@ class Series(NDFrame):
|
|||||||
if isinstance(other, Series):
|
if isinstance(other, Series):
|
||||||
# Need to use scripted query to compare to values
|
# Need to use scripted query to compare to values
|
||||||
painless = f"doc['{self.name}'].value == doc['{other.name}'].value"
|
painless = f"doc['{self.name}'].value == doc['{other.name}'].value"
|
||||||
return ScriptFilter(painless)
|
return ScriptFilter(painless, lang="painless")
|
||||||
elif isinstance(other, (int, float)):
|
elif isinstance(other, (int, float)):
|
||||||
return Equal(field=self.name, value=other)
|
return Equal(field=self.name, value=other)
|
||||||
elif isinstance(other, str):
|
elif isinstance(other, str):
|
||||||
@ -461,7 +461,7 @@ class Series(NDFrame):
|
|||||||
if isinstance(other, Series):
|
if isinstance(other, Series):
|
||||||
# Need to use scripted query to compare to values
|
# Need to use scripted query to compare to values
|
||||||
painless = f"doc['{self.name}'].value != doc['{other.name}'].value"
|
painless = f"doc['{self.name}'].value != doc['{other.name}'].value"
|
||||||
return ScriptFilter(painless)
|
return ScriptFilter(painless, lang="painless")
|
||||||
elif isinstance(other, (int, float)):
|
elif isinstance(other, (int, float)):
|
||||||
return NotFilter(Equal(field=self.name, value=other))
|
return NotFilter(Equal(field=self.name, value=other))
|
||||||
elif isinstance(other, str):
|
elif isinstance(other, str):
|
||||||
|
@ -44,11 +44,12 @@ class TestOperators:
|
|||||||
assert IsNull("a").build() == {"missing": {"field": "a"}}
|
assert IsNull("a").build() == {"missing": {"field": "a"}}
|
||||||
assert NotNull("a").build() == {"exists": {"field": "a"}}
|
assert NotNull("a").build() == {"exists": {"field": "a"}}
|
||||||
assert ScriptFilter(
|
assert ScriptFilter(
|
||||||
'doc["num1"].value > params.param1', params={"param1": 5}
|
'doc["num1"].value > params.param1', lang="painless", params={"param1": 5}
|
||||||
).build() == {
|
).build() == {
|
||||||
"script": {
|
"script": {
|
||||||
"script": {
|
"script": {
|
||||||
"inline": 'doc["num1"].value > params.param1',
|
"lang": "painless",
|
||||||
|
"source": 'doc["num1"].value > params.param1',
|
||||||
"params": {"param1": 5},
|
"params": {"param1": 5},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user