Filtering a search via scripting
In Chapter 5, Search, we've seen many filters. Elasticsearch scripting allows the extension of a traditional filter with custom scripts.
Using scripting to create a custom filter is a convenient way to write scripting rules not provided by Lucene or Elasticsearch, and to implement business logic not available in a DSL query.
Getting ready
You need an up-and-running Elasticsearch installation as we described in the Downloading and installing Elasticsearch recipe in Chapter 2, Downloading and Setup.
To execute curl
via the command-line you need to install curl
for your operating system.
To correctly execute the following commands, you need an index populated with the script (chapter_09/populate_for_scripting.sh
) available in the online code and Javascript/Python Language scripting plugins installed.
How to do it...
For filtering a search using script, we will perform the following steps:
We'll write a search with a filter that filters out a document with an age value...