* [docs] Migrate docs from AsciiDoc to Markdown (#123507) * delete asciidoc files * add migrated files * fix errors * Disable docs tests * Clarify release notes page titles * Revert "Clarify release notes page titles" This reverts commit8be688648d
. * Comment out edternal URI images * Clean up query languages landing pages, link to conceptual docs * Add .md to url * Fixes inference processor nesting. --------- Co-authored-by: Liam Thompson <32779855+leemthompo@users.noreply.github.com> Co-authored-by: Liam Thompson <leemthompo@gmail.com> Co-authored-by: Martijn Laarman <Mpdreamz@gmail.com> Co-authored-by: István Zoltán Szabó <szabosteve@gmail.com> (cherry picked from commitb7e3a1e14b
) # Conflicts: # docs/build.gradle # docs/reference/migration/index.asciidoc # docs/reference/migration/migrate_9_0.asciidoc # docs/reference/release-notes.asciidoc # docs/reference/release-notes/9.0.0.asciidoc # docs/reference/release-notes/highlights.asciidoc * Fix build file * Really fix build file --------- Co-authored-by: Colleen McGinnis <colleen.j.mcginnis@gmail.com>
3.2 KiB
navigation_title | mapped_pages | |
---|---|---|
Script |
|
Script query [query-dsl-script-query]
::::{note}
Runtime fields provide a very similar feature that is more flexible. You write a script to create field values and they are available everywhere, such as fields
, all queries, and aggregations.
::::
Filters documents based on a provided script. The script
query is typically used in a filter context.
::::{warning} Using scripts can result in slower search speeds. See Scripts, caching, and search speed. ::::
Example request [script-query-ex-request]
GET /_search
{
"query": {
"bool": {
"filter": {
"script": {
"script": """
double amount = doc['amount'].value;
if (doc['type'].value == 'expense') {
amount *= -1;
}
return amount < 10;
"""
}
}
}
}
}
You can achieve the same results in a search query by using runtime fields. Use the fields
parameter on the _search
API to fetch values as part of the same query:
GET /_search
{
"runtime_mappings": {
"amount.signed": {
"type": "double",
"script": """
double amount = doc['amount'].value;
if (doc['type'].value == 'expense') {
amount *= -1;
}
emit(amount);
"""
}
},
"query": {
"bool": {
"filter": {
"range": {
"amount.signed": { "lt": 10 }
}
}
}
},
"fields": [{"field": "amount.signed"}]
}
Top-level parameters for script
[script-top-level-params]
script
- (Required, script object) Contains a script to run as a query. This script must return a boolean value,
true
orfalse
.
Notes [script-query-notes]
Custom parameters [script-query-custom-params]
Like filters, scripts are cached for faster execution. If you frequently change the arguments of a script, we recommend you store them in the script’s params
parameter. For example:
GET /_search
{
"query": {
"bool": {
"filter": {
"script": {
"script": {
"source": "doc['num1'].value > params.param1",
"lang": "painless",
"params": {
"param1": 5
}
}
}
}
}
}
}
Allow expensive queries [_allow_expensive_queries_4]
Script queries will not be executed if search.allow_expensive_queries
is set to false.