Support for multi nested paths and filters in sorts
mohak-cf opened this issue · 2 comments
Elasticsearch provides a way to have multiple nested paths in a sort field, documentation example -
https://www.elastic.co/guide/en/elasticsearch/reference/6.8/search-request-sort.html#_nested_sorting_examples
ElasticBuilder only supports adding a path and a filter in the nested query for sort, i.e
nested(nested: { path: string, filter: Query }): this;
There should also be support for adding another nested type object.
There is no hard restriction against setting an object with another nested object. If you are using Typescript, you can add an ignore directive for the same(// @ts-ignore
). I will incorporate this suggestion for the next package release.
Thanks @sudo-suhas -- I didn't know you can pass props to the fns and they won't get dropped!
@mohak-cf & anyone who stumbles on this in the future -- here's a what I ended up going with:
sort("deeply.nested.numericField")
.mode("min")
.order("asc")
.nested({
path: "deeply",
filter: termsQuery("deeply.fieldToFilter", ["a", "b", "c"]),
// @ts-ignore
nested: {
path: "deeply.nested",
filter: termQuery("deeply.nested.anotherFieldToFilter", "xyz")
}
});