In Chapter 5, Search, Queries, and Filters, we have learnt about filters. ElasticSearch scripting allows you to extend the traditional filter with custom scripts.
Using scripting to create a custom filter is a convenient way to write scripting rules that are not provided by Lucene or ElasticSearch, and to implement business logic that is not available in the query DSL.
You will need a working ElasticSearch cluster and an index populated with the (chapter_06/populate_aggregations.sh
) script used in Chapter 6, Aggregations, which is available at https://github.com/aparo/elasticsearch-cookbook-second-edition.
In order to filter a search using a script, perform the following steps:
Write a search with a filter that filters out a document with the value of age less than the parameter value:
curl -XGET 'http://127.0.0.1:9200/test-index/test-type/_search?&pretty=true&size=3' -d '{ "query": { "filtered": { "filter": { ...