mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Docs: Prepare plugin and integration docs for 2.0
* Centralised plugin docs in docs/plugins/ * Moved integrations into same docs * Moved community clients into the clients section of the docs * Removed docs/community Closes #11734 Closes #11724 Closes #11636 Closes #11635 Closes #11632 Closes #11630 Closes #12046 Closes #12438 Closes #12579
This commit is contained in:
parent
42300938aa
commit
e143c6e460
49 changed files with 4444 additions and 3503 deletions
192
docs/plugins/lang-python.asciidoc
Normal file
192
docs/plugins/lang-python.asciidoc
Normal file
|
@ -0,0 +1,192 @@
|
|||
[[lang-python]]
|
||||
=== Python Language Plugin
|
||||
|
||||
The Python language plugin enables the use of Python in Elasticsearch
|
||||
scripts, via the http://www.jython.org/[Jython] Java implementation of Python.
|
||||
|
||||
[[lang-python-install]]
|
||||
[float]
|
||||
==== Installation
|
||||
|
||||
This plugin can be installed using the plugin manager:
|
||||
|
||||
[source,sh]
|
||||
----------------------------------------------------------------
|
||||
sudo bin/plugin install lang-python
|
||||
----------------------------------------------------------------
|
||||
|
||||
The plugin must be installed on every node in the cluster, and each node must
|
||||
be restarted after installation.
|
||||
|
||||
[[lang-python-remove]]
|
||||
[float]
|
||||
==== Removal
|
||||
|
||||
The plugin can be removed with the following command:
|
||||
|
||||
[source,sh]
|
||||
----------------------------------------------------------------
|
||||
sudo bin/plugin remove lang-python
|
||||
----------------------------------------------------------------
|
||||
|
||||
The node must be stopped before removing the plugin.
|
||||
|
||||
[[lang-python-usage]]
|
||||
==== Using Python in Elasticsearch
|
||||
|
||||
Once the plugin has been installed, Python can be used at a scripting
|
||||
language by setting the `lang` parameter to `python`.
|
||||
|
||||
Scripting is available in many APIs, but we will use an example with the
|
||||
`function_score` for demonstration purposes:
|
||||
|
||||
[[lang-python-inline]]
|
||||
[float]
|
||||
=== Inline scripts
|
||||
|
||||
WARNING: Enabling inline scripting on an unprotected Elasticsearch cluster is dangerous.
|
||||
See <<lang-python-file>> for a safer option.
|
||||
|
||||
If you have enabled {ref}/modules-scripting.html#enable-dynamic-scripting[inline scripts],
|
||||
you can use Python as follows:
|
||||
|
||||
[source,json]
|
||||
----
|
||||
DELETE test
|
||||
|
||||
PUT test/doc/1
|
||||
{
|
||||
"num": 1.0
|
||||
}
|
||||
|
||||
PUT test/doc/2
|
||||
{
|
||||
"num": 2.0
|
||||
}
|
||||
|
||||
GET test/_search
|
||||
{
|
||||
"query": {
|
||||
"function_score": {
|
||||
"script_score": {
|
||||
"script": {
|
||||
"inline": "doc[\"num\"].value * factor",
|
||||
"lang": "python",
|
||||
"params": {
|
||||
"factor": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
----
|
||||
// AUTOSENSE
|
||||
|
||||
[[lang-python-indexed]]
|
||||
[float]
|
||||
=== Indexed scripts
|
||||
|
||||
WARNING: Enabling indexed scripting on an unprotected Elasticsearch cluster is dangerous.
|
||||
See <<lang-python-file>> for a safer option.
|
||||
|
||||
If you have enabled {ref}/modules-scripting.html#enable-dynamic-scripting[indexed scripts],
|
||||
you can use Python as follows:
|
||||
|
||||
[source,json]
|
||||
----
|
||||
DELETE test
|
||||
|
||||
PUT test/doc/1
|
||||
{
|
||||
"num": 1.0
|
||||
}
|
||||
|
||||
PUT test/doc/2
|
||||
{
|
||||
"num": 2.0
|
||||
}
|
||||
|
||||
POST _scripts/python/my_script <1>
|
||||
{
|
||||
"script": "doc[\"num\"].value * factor"
|
||||
}
|
||||
|
||||
GET test/_search
|
||||
{
|
||||
"query": {
|
||||
"function_score": {
|
||||
"script_score": {
|
||||
"script": {
|
||||
"id": "my_script", <2>
|
||||
"lang": "python",
|
||||
"params": {
|
||||
"factor": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
----
|
||||
// AUTOSENSE
|
||||
|
||||
<1> We index the script under the id `my_script`.
|
||||
<2> The function score query retrieves the script with id `my_script`.
|
||||
|
||||
|
||||
[[lang-python-file]]
|
||||
[float]
|
||||
=== File scripts
|
||||
|
||||
You can save your scripts to a file in the `config/scripts/` directory on
|
||||
every node. The `.python` file suffix identifies the script as containing
|
||||
Python:
|
||||
|
||||
First, save this file as `config/scripts/my_script.python` on every node
|
||||
in the cluster:
|
||||
|
||||
[source,python]
|
||||
----
|
||||
doc["num"].value * factor
|
||||
----
|
||||
|
||||
then use the script as follows:
|
||||
|
||||
[source,json]
|
||||
----
|
||||
DELETE test
|
||||
|
||||
PUT test/doc/1
|
||||
{
|
||||
"num": 1.0
|
||||
}
|
||||
|
||||
PUT test/doc/2
|
||||
{
|
||||
"num": 2.0
|
||||
}
|
||||
|
||||
GET test/_search
|
||||
{
|
||||
"query": {
|
||||
"function_score": {
|
||||
"script_score": {
|
||||
"script": {
|
||||
"file": "my_script", <1>
|
||||
"lang": "python",
|
||||
"params": {
|
||||
"factor": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
----
|
||||
// AUTOSENSE
|
||||
|
||||
<1> The function score query retrieves the script with filename `my_script.python`.
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue