* Reorganize scripting documentation
* Further changes to tidy up scripting docs
Closeselastic#18116
* Add note about .lat/lon potentially returning null
* Added .value to expressions example
* Fixed two bad ASCIIDOC links
experimental[The functionality described on this page is considered experimental and may be changed or removed in a future release]
Text features, such as term or document frequency for a specific term can be accessed in scripts (see <<modules-scripting, scripting documentation>> ) with the `_index` variable. This can be useful if, for example, you want to implement your own scoring model using for example a script inside a <<query-dsl-function-score-query,function score query>>.
Text features, such as term or document frequency for a specific term can be
accessed in scripts with the `_index` variable. This can be useful if, for
example, you want to implement your own scoring model using for example a
script inside a <<query-dsl-function-score-query,function score query>>.
Statistics over the document collection are computed *per shard*, not per
index.
[float]
==== Nomenclature:
=== Nomenclature:
[horizontal]
@@ -33,7 +37,7 @@ depending on the shard the current document resides in.
[float]
==== Shard statistics:
=== Shard statistics:
`_index.numDocs()`::
@@ -49,7 +53,7 @@ depending on the shard the current document resides in.
[float]
==== Field statistics:
=== Field statistics:
Field statistics can be accessed with a subscript operator like this:
`_index['FIELD']`.
@@ -74,7 +78,7 @@ depending on the shard the current document resides in.
The number of terms in a field cannot be accessed using the `_index` variable. See <<token-count>> for how to do that.
[float]
==== Term statistics:
=== Term statistics:
Term statistics for a field can be accessed with a subscript operator like
this: `_index['FIELD']['TERM']`. This will never return null, even if term or field does not exist.
@@ -101,7 +105,7 @@ affect is your set the <<index-options,`index_options`>> to `docs`.
[float]
==== Term positions, offsets and payloads:
=== Term positions, offsets and payloads:
If you need information on the positions of terms in a field, call
`_index['FIELD'].get('TERM', flag)` where flag can be
@@ -174,7 +178,7 @@ return score;
[float]
==== Term vectors:
=== Term vectors:
The `_index` variable can only be used to gather statistics for single terms. If you want to use information on all terms in a field, you must store the term vectors (see <<term-vector>>). To access them, call
Lucene's expressions compile a `javascript` expression to bytecode. They are
designed for high-performance custom ranking and sorting functions and are
enabled for `inline` and `stored` scripting by default.
[float]
=== Performance
Expressions were designed to have competitive performance with custom Lucene code.
This performance is due to having low per-document overhead as opposed to other
scripting engines: expressions do more "up-front".
This allows for very fast execution, even faster than if you had written a `native` script.
[float]
=== Syntax
Expressions support a subset of javascript syntax: a single expression.
See the link:http://lucene.apache.org/core/6_0_0/expressions/index.html?org/apache/lucene/expressions/js/package-summary.html[expressions module documentation]
for details on what operators and functions are available.
Variables in `expression` scripts are available to access:
* document fields, e.g. `doc['myfield'].value`
* variables and methods that the field supports, e.g. `doc['myfield'].empty`
* Parameters passed into the script, e.g. `mymodifier`
* The current document's score, `_score` (only available when used in a `script_score`)
You can use Expressions scripts for `script_score`, `script_fields`, sort scripts, and numeric aggregation
scripts, simply set the `lang` parameter to `expression`.
In this example the coordinates could have been passed as parameters to the script,
e.g. based on geolocation of the user.
[float]
=== Limitations
There are a few limitations relative to other script languages:
* Only numeric, boolean, date, and geo_point fields may be accessed
* Stored fields are not available
Oops, something went wrong.
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.
We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products.
Learn more.
We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products.
You can always update your selection by clicking Cookie Preferences at the bottom of the page.
For more information, see our Privacy Statement.
Essential cookies
We use essential cookies to perform essential website functions, e.g. they're used to log you in.
Learn more
Always active
Analytics cookies
We use analytics cookies to understand how you use our websites so we can make them better, e.g. they're used to gather information about the pages you visit and how many clicks you need to accomplish a task.
Learn more
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sync loggly fork with current master #2
Sync loggly fork with current master #2
Changes from 1 commit
99aad3d22dc06f1a321febe239b834b583910f9df3946c7e4cb29e04a0ba3c96302fb672fb93e0cf1d166c3beaac25f8ad04bd55d2636703713c0df6c7a44cbaceabd2232a7c8c7739937382ecf349c4f07c2fbf7aca138a31b94ee322903b2ce2f5262a814c82e5640b41580cf1d0d59162fd27c8397d4cf53859fee8c728409e4372eceb8e178c48bdda49226679c15f33e616c4c250c6d6a5693c1f6fff82db0eed5cf0a6f40c98dba261385e25d01526b85d2fc03ca02d6564825321e94e68397328ca21aa0929187cd63362c8bdd31980dbe3151a53c5a8bf759ad8bf536b9ac469a90bdc6f15f35ffcb1323bc926b283a6d2247b5c82dea4499fe5ce9052191f78d615f52eb6f3c4554fe8d3427b223d67dfad07055a0cfdd34d90b04c6cf7e7656d7e124e8e567c0734230697ce49d21b07d8b3e784c9e58fc513821d716f928e2b959c135b66e8529e11b96c2cae5754b1c1163912761c4090a18ff699ee3ce6c9f3b2ab82d2b2320f778c9f1fb6a3443976d1199cd8e16af607d87087c55df19de8354db91df364ddf9167d14728e88ac1193567a2d3c5f867b69e4eb12a423b6698c3e839dade90d00fcb40b98d52537d473be01f270ed2ddebbb9901c25b0ff56521d5b9f10eaa8315be79ed3d1be072c3d3d99988105d0d2d2bc1afcb5c740feb10e3b37a78cdcd4ae5c0db352a90000dd623a468120f36c7425289343f59408ef2e3a88c52e883f3fa59b7d02fb7d1fd1752cdac46094704aef78ce214ce31ded91d5ddc531e0970c595b6f9abe54c24dfdae97aeed5b0b5a7edf9ba2fe155d8f68468e7ac4f481492b6556e27bf8e6717225d93aeb66802cf4298972f392e613f4b6a149193d1b38243c9e7667a091557fc8b319ca821c54033a45e1cc0660386546aed87a47d33ad5ce59eb1b2cf81c0b7b1c2d3b106a4f647753420a0ffe6ee8ddf5def6a7631dfbe8b531dcbfddc2c1f1d80542a63285a2bf585e5f0cc795644f49abb015b389ef46632bb4c2e4f87dd8b373c30b5b4f9d12f7b7689a1afe05ee86d288deae01a4f97a41eed0edd13e4edee5866a545d790c7680bb46b2764b47ce4af4b5189eb420af482fced8da189341d6b4e47bc5532d38adfd603b66d4025dd642d3142e3930a2158871fdd113e2399fbbd7328164cc9d5537d9ce96f55ee5cc294317b10830bd42e258379b2b474ec4825ddf4323010381de8155e1ef9667dbFile filter...
Jump to…
Reorganise scripting docs (elastic#18132)