Skip to content

Conversation

@nik9000
Copy link
Member

@nik9000 nik9000 commented Aug 24, 2022

This adds the sortable option to the filters agg which modifies the
rendered json for named filters from

"buckets": { "filtera": {}, "filterb": {}, "filterc": {} } 

to:

"buckets": [ { "filtera": {} }, { "filterb": {} }, { "filterc": {} } ] 

That way when you sort the buckets, you can see the ordering. The json
parser won't throw it away.

Also drops the keyed parameter from the spec for filters - it
doesn't exist.

@nik9000
Copy link
Member Author

nik9000 commented Aug 24, 2022

This adds the `sortable` option to the `filters` agg which modifies the rendered json for named filters from ``` "buckets": { "filtera": {}, "filterb": {}, "filterc": {} } ``` to: ``` "buckets": [ { "filtera": {} }, { "filterb": {} }, { "filterc": {} } ] ``` That way when you sort the buckets, you can see the ordering. The json parser won't throw it away. Also drops the `keyed` parameter from the spec for `filters` - it doesn't exist.
Copy link
Contributor

@swallez swallez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a fundamentally flawed assumption in elastic/elasticsearch#89256, which is that JSON objects properties are ordered (filters in this context). This isn't the case, and depending on how users build their query, order in the JSON may not be the insertion order since a JSON object is basically a map.

Furthermore, it's good to limit the number of "shapes" of a data structure, as these lead to union types that 1/ aren't natively supported by every language (e.g. Java or Go) and 2/ require the user to downcast the object to a specific variant with the possible runtime errors that can result from that.

So for use cases where filter order matters, this should be implemented in the application and not as an additional representation of the result driven by a request parameter.

@nik9000
Copy link
Member Author

nik9000 commented Aug 29, 2022

There's a fundamentally flawed assumption in elastic/elasticsearch#89256, which is that JSON objects properties are ordered (filters in this context). This isn't the case, and depending on how users build their query, order in the JSON may not be the insertion order since a JSON object is basically a map.

That PR is attempting to fix that assumption. It provides the option to return an array.

So for use cases where filter order matters, this should be implemented in the application and not as an additional representation of the result driven by a request parameter.

We've had support for ordering on the ES side for the better part of forever now. They are trying to make it so you don't have to rely on the ordering in the json objects. Personally, I'd do the sorting client side too. But because we support it for other aggs and don't fail when you point it at this one, it makes some sense to support it. Thus we never closed this bug as WONTFIX. But if the overhead from the extra shapes is too high then we should reject the PR and close the bug as something we won't implement.

@sethmlarson
Copy link
Contributor

@nik9000 Thanks for opening this PR to discuss. I'm in agreement with Sylvain about adding more potential shapes and unions to already complicated structures would be a lot of overhead for us.

@sethmlarson
Copy link
Contributor

Closing this PR in favor of the suggestion here: elastic/elasticsearch#83957 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants