Skip to content

Commit 0b86ab3

Browse files
committed
use params for script.
1 parent 4666f9e commit 0b86ab3

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

stac_fastapi/core/stac_fastapi/core/models/patch.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pydantic import BaseModel, computed_field, model_validator
77

88
regex = re.compile(r"([^.' ]*:[^.'[ ]*)\.?")
9+
replacements = str.maketrans({"/": "", ".": "", ":": "", "[": "", "]": ""})
910

1011

1112
class ESCommandSet:
@@ -153,3 +154,13 @@ def variable_name(self) -> str:
153154
return (
154155
f"{self.nest.replace('.','_').replace(':','_')}_{self.key.replace(':','_')}"
155156
)
157+
158+
@computed_field # type: ignore[misc]
159+
@property
160+
def param_key(self) -> str:
161+
"""Param key for scripting.
162+
163+
Returns:
164+
str: param key
165+
"""
166+
return self.path.translate(replacements)

stac_fastapi/core/stac_fastapi/core/utilities.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ def add_commands(
316316
operation: PatchOperation,
317317
path: ElasticPath,
318318
from_path: ElasticPath,
319+
params: Dict,
319320
) -> None:
320321
"""Add value at path.
321322
@@ -332,7 +333,8 @@ def add_commands(
332333
else f"ctx._source.{from_path.es_path}"
333334
)
334335
else:
335-
value = operation.json_value
336+
value = f"params.{path.param_key}"
337+
params[path.param_key] = operation.json_value
336338

337339
if path.index is not None:
338340
commands.add(
@@ -372,6 +374,8 @@ def operations_to_script(operations: List) -> Dict:
372374
Dict: elasticsearch update script.
373375
"""
374376
commands: ESCommandSet = ESCommandSet()
377+
params: Dict = {}
378+
375379
for operation in operations:
376380
path = ElasticPath(path=operation.path)
377381
from_path = (
@@ -390,7 +394,11 @@ def operations_to_script(operations: List) -> Dict:
390394

391395
if operation.op in ["add", "replace", "copy", "move"]:
392396
add_commands(
393-
commands=commands, operation=operation, path=path, from_path=from_path
397+
commands=commands,
398+
operation=operation,
399+
path=path,
400+
from_path=from_path,
401+
params=params,
394402
)
395403

396404
if operation.op == "test":
@@ -401,4 +409,5 @@ def operations_to_script(operations: List) -> Dict:
401409
return {
402410
"source": source,
403411
"lang": "painless",
412+
"params": params,
404413
}

0 commit comments

Comments
 (0)