Created
July 5, 2018 09:44
-
-
Save aplz/cc6f5071eb76f09c2b5e0d660a949e64 to your computer and use it in GitHub Desktop.
elasticsearch: script query to filter by number of items in field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create the script query | |
ScriptQueryBuilder scriptQuery = QueryBuilders.scriptQuery(new Script("params._source.your_field.size() > 1")); | |
// add the query in a boolean term to enforce the filter | |
client.prepareSearch(indices).setQuery(QueryBuilders.boolQuery().must(scriptQuery)).get(); | |
// the response will only contain documents whith more than one item in the field "your_field" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment