-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script: Fields API for Filter context (#76119)
- Loading branch information
1 parent
b62ab7e
commit bb9c91f
Showing
10 changed files
with
209 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
.../main/resources/org/elasticsearch/painless/spi/org.elasticsearch.script.fields.filter.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
# or more contributor license agreements. Licensed under the Elastic License | ||
# 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
# in compliance with, at your election, the Elastic License 2.0 or the Server | ||
# Side Public License, v 1. | ||
# | ||
|
||
# The whitelist for the fields api | ||
|
||
# The scripts must be whitelisted for painless to find the classes for the field API | ||
class org.elasticsearch.script.FilterScript @no_import { | ||
} | ||
class org.elasticsearch.script.FilterScript$Factory @no_import { | ||
} |
160 changes: 160 additions & 0 deletions
160
...es/lang-painless/src/yamlRestTest/resources/rest-api-spec/test/painless/40_fields_api.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
# Integration tests for sort script queries using Painless | ||
|
||
setup: | ||
- skip: | ||
version: " - 7.14.99" | ||
reason: "sort script fields api was added in 7.15.0" | ||
|
||
--- | ||
"sort script fields api": | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
settings: | ||
number_of_shards: 2 | ||
mappings: | ||
properties: | ||
dval: | ||
type: double | ||
- do: | ||
index: | ||
index: test | ||
id: d1 | ||
body: {"dval": 10, "sval": "f"} | ||
- do: | ||
index: | ||
index: test | ||
id: d2 | ||
body: {} | ||
- do: | ||
index: | ||
index: test | ||
id: d3 | ||
body: {"dval": 5, "sval": "a"} | ||
- do: | ||
indices.refresh: {} | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
sort: | ||
_script: | ||
type: number | ||
script: | ||
source: "field('dval').getValue(3)" | ||
- match: { hits.total: 3 } | ||
- match: { hits.hits.0._id: d2 } | ||
- match: { hits.hits.1._id: d3 } | ||
- match: { hits.hits.2._id: d1 } | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
sort: | ||
_script: | ||
type: string | ||
script: | ||
source: "field('sval.keyword').getValue('g')" | ||
- match: { hits.total: 3 } | ||
- match: { hits.hits.0._id: d3 } | ||
- match: { hits.hits.1._id: d1 } | ||
- match: { hits.hits.2._id: d2 } | ||
|
||
--- | ||
"script score fields api": | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
settings: | ||
number_of_shards: 2 | ||
mappings: | ||
properties: | ||
dval: | ||
type: double | ||
- do: | ||
index: | ||
index: test | ||
id: d1 | ||
body: {"dval": 10} | ||
- do: | ||
index: | ||
index: test | ||
id: d2 | ||
body: {} | ||
- do: | ||
index: | ||
index: test | ||
id: d3 | ||
body: {"dval": 5} | ||
- do: | ||
indices.refresh: {} | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
index: test | ||
body: | ||
query: | ||
script_score: | ||
query: {match_all: {} } | ||
script: | ||
source: "field('dval').getValue(3)" | ||
- match: { hits.total: 3 } | ||
- match: { hits.hits.0._id: d1 } | ||
- match: { hits.hits.1._id: d3 } | ||
- match: { hits.hits.2._id: d2 } | ||
|
||
--- | ||
"filter script fields api": | ||
- do: | ||
indices.create: | ||
index: test | ||
body: | ||
settings: | ||
number_of_shards: 2 | ||
mappings: | ||
properties: | ||
dval: | ||
type: double | ||
- do: | ||
index: | ||
index: test | ||
id: d1 | ||
body: {"dval": 10, "sval": "f"} | ||
- do: | ||
index: | ||
index: test | ||
id: d2 | ||
body: {} | ||
- do: | ||
index: | ||
index: test | ||
id: d3 | ||
body: {"dval": 5, "sval": "a"} | ||
- do: | ||
indices.refresh: {} | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
bool: | ||
filter: | ||
script: | ||
script: "field('dval').getValue(6) > 6" | ||
- match: { hits.total: 1 } | ||
- match: { hits.hits.0._id: d1 } | ||
- do: | ||
search: | ||
rest_total_hits_as_int: true | ||
body: | ||
query: | ||
bool: | ||
filter: | ||
script: | ||
script: "field('sval.keyword').getValue('b') == 'a'" | ||
- match: { hits.total: 1 } | ||
- match: { hits.hits.0._id: d3 } |
65 changes: 0 additions & 65 deletions
65
...less/src/yamlRestTest/resources/rest-api-spec/test/painless/40_sort_script_fields_api.yml
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
...ess/src/yamlRestTest/resources/rest-api-spec/test/painless/88_script_score_fields_api.yml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.