diff --git a/src/Search/Sorting/Sort.php b/src/Search/Sorting/Sort.php index 8a6ec4b..cdfeb52 100644 --- a/src/Search/Sorting/Sort.php +++ b/src/Search/Sorting/Sort.php @@ -65,7 +65,7 @@ public function toDSL(): array $details['order'] = $this->order; - return [$this->field => $details]; + return [$this->script !== null ? '_script' : $this->field => $details]; } public function __toString(): string diff --git a/src/Search/Sorting/SortBuilder.php b/src/Search/Sorting/SortBuilder.php index a887efe..c990c7b 100644 --- a/src/Search/Sorting/SortBuilder.php +++ b/src/Search/Sorting/SortBuilder.php @@ -49,7 +49,7 @@ public function sortBy(string $field, string $order = SortOrder::ASC, ?string $m public function sortByScript(Script $script, string $type = ScriptSortType::NUMBER, string $order = SortOrder::ASC): static { $sort = new Sort( - field: '_script', + field: '_script' . md5(json_encode($script->toDSL())), order: $order, type: $type, script: $script,