Skip to content

Cannot build valid 'nested' queries in filter context #183

@cricketts

Description

@cricketts

From what I can tell, it's not possible to perform a nested query inside of a filter context with BodyBuilder:

bodybuilder().orFilter('nested', 'path', 'my_path', b => 
  b.query('term', 'my_path.my_field', 'my_value')
)

This doesn't work because b.query does not exist, and instead only various filter functions are available. I believe this has to do with being in the "filter context" because of the outer orFilter().

If I try to use filter, however:

bodybuilder().orFilter('nested', 'path', 'my_path', b => 
  b.filter('term', 'my_path.my_field', 'my_value')
)

This results in a 400 Bad Request from Elasticsearch because filters inside of a nested field is not supported. I am running against Elasticsearch v6.2.

If I use an orQuery at the top-level this works fine:

bodybuilder().orQuery('nested', 'path', 'my_path', b => 
  b.query('term', 'my_path.my_field', 'my_value')
)

However this doesn't work for me because I want my boolean condition to live in the filter context with my other conditions and it's cheaper to perform.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions