OpenSearch/docs/painless
Martijn van Groningen 1924f5d07c
Add more contexts to painless execute api (#30511)
This change adds two contexts the execute scripts against:

* SEARCH_SCRIPT: Allows to run scripts in a search script context.
This context is used in `function_score` query's script function,
script fields, script sorting and `terms_set` query.

* FILTER_SCRIPT: Allows to run scripts in a filter script context.
This context is used in the `script` query.

In both contexts a index name needs to be specified and a sample document.
The document is needed to create an in-memory index that the script can
access via the `doc[...]` and other notations. The index name is needed
because a mapping is needed to index the document.

Examples:

```
POST /_scripts/painless/_execute
{
  "script": {
    "source": "doc['field'].value.length()"
  },
  "context" : {
    "search_script": {
      "document": {
        "field": "four"
      },
      "index": "my-index"
    }
  }
}
```

Returns:

```
{
  "result": 4
}
```

POST /_scripts/painless/_execute
{
  "script": {
    "source": "doc['field'].value.length() <= params.max_length",
    "params": {
      "max_length": 4
    }
  },
  "context" : {
    "filter_script": {
      "document": {
        "field": "four"
      },
      "index": "my-index"
    }
  }
}

Returns:

```
{
  "result": true
}
```

Also changed PainlessExecuteAction.TransportAction to use TransportSingleShardAction
instead of HandledAction, because now in case score or filter contexts are used
the request needs to be redirected to a node that has an active IndexService
for the index being referenced (a node with a shard copy for that index).
2018-07-18 12:42:07 +02:00
..
painless-api-reference Fix some links in Painless method reference 2017-08-17 10:50:38 -04:00
painless-contexts Painless: Add Context Docs (#31190) 2018-07-02 14:44:36 -07:00
index.asciidoc Painless: Add Context Docs (#31190) 2018-07-02 14:44:36 -07:00
painless-api-reference.asciidoc Painless Spec Documentation Clean Up (#29441) 2018-04-17 12:16:08 -07:00
painless-casting.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-comments.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-contexts.asciidoc Painless: Add Context Docs (#31190) 2018-07-02 14:44:36 -07:00
painless-debugging.asciidoc Change ScriptException status to 400 (bad request) (#30861) 2018-05-30 14:00:07 +02:00
painless-description.asciidoc Painless Spec Documentation Clean Up (#29441) 2018-04-17 12:16:08 -07:00
painless-execute-script.asciidoc Add more contexts to painless execute api (#30511) 2018-07-18 12:42:07 +02:00
painless-functions.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-getting-started.asciidoc [DOCS] Fix broken link in painless example 2018-07-09 10:47:42 -07:00
painless-identifiers.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-keywords.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-lambdas.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-lang-spec.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-literals.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-operators-array.asciidoc Painless: Add Context Docs (#31190) 2018-07-02 14:44:36 -07:00
painless-operators-boolean.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-operators-general.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-operators-numeric.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-operators-reference.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-operators.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-regexes.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-scripts.asciidoc Painless: Add Context Docs (#31190) 2018-07-02 14:44:36 -07:00
painless-statements.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-types.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-variables.asciidoc Painless: Restructure/Clean Up of Spec Documentation (#31013) 2018-06-07 17:11:56 -07:00
painless-xref.asciidoc [DOCS] Setting up separate Painless book. 2017-05-16 12:46:56 -07:00