Script Filter

edit

See Script Filter

FilterBuilder filter = FilterBuilders.scriptFilter(
        "doc['age'].value > param1"
    ).addParam("param1", 10);

Note that you can cache the result using ScriptFilterBuilder#cache(boolean) method. See Caching.