Skip to content

Instantly share code, notes, and snippets.

@xethorn
xethorn / elasticsearch_min_max_children_with_nested_datatypes.md
Last active April 28, 2021 02:02
Elasticsearch: min_children and max_children with nested datatypes for Elastic 6 and 7+.

Elasticsearch: Min and Max Children Query with Nested Datatypes

Elasticsearch does not support min_children and max_children for nested datatypes by default (see: issue #10043). In case you need this behavior, this gist provides an alternative solution. Please note that I haven't benchmarked it against join queries.

Alternative solution

To support min_children and max_children for your nested query, all you have to do is to use a function_score query. To make this more concrete: you have an index called Person with the following mapping:

  • first_name (text)
  • email (text)