Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8.15.6 - Sorting Feedback #8350

Open
Tracked by #8356
niemyjski opened this issue Sep 16, 2024 · 0 comments
Open
Tracked by #8356

8.15.6 - Sorting Feedback #8350

niemyjski opened this issue Sep 16, 2024 · 0 comments

Comments

@niemyjski
Copy link
Contributor

Elastic.Clients.Elasticsearch version: 8.15.6

Elasticsearch version: 8.15.1

.NET runtime version: 8.x

Operating system version: Any

Description of the problem including expected versus actual behavior:

Sorting with the new client is insanely verbose and tedious, to the point I don't even want to convert the tests we have...

Example 1

// Previous
Client.Search<MyType>(d => d.Index(index).Aggregations(a => a
            .Terms("terms_field1", t => t
                .Field("field1.keyword")
                .Order(o => o.Descending("cardinality_field4"))));


// New
await Client.SearchAsync<MyType>(d => d.Index(index).Aggregations(a => a
                .Add("terms_field1", a1 => a1
                    .Terms(t => t.Field("field1.keyword").Order(new List<KeyValuePair<Field, SortOrder>> { new ("cardinality_field4", SortOrder.Desc) })))));

Example 2

// Previous
if (termsAggregation != null && (child.Prefix == "-" || child.Prefix == "+"))
            {
                if (termsAggregation.Order == null)
                    termsAggregation.Order = new List<TermsOrder>();

                termsAggregation.Order.Add(new TermsOrder
                {
                    Key = ((IAggregation)aggregation).Name,
                    Order = child.Prefix == "-" ? SortOrder.Descending : SortOrder.Ascending
                });
            }


// New
            if (termsAggregation != null && child.Prefix is "-" or "+")
            {
                termsAggregation.Order ??= new List<KeyValuePair<Field, SortOrder>>();
                termsAggregation.Order.Add(new KeyValuePair<Field, SortOrder>(aggregation.Name, child.Prefix == "-" ? SortOrder.Desc : SortOrder.Asc));
            }

Example 3 (I don't even want to think about converting)

await Client.SearchAsync<MyType>(d => d.Index(index).Sort(s => s
            .Field(f => f.Field(new Field("field3")).Ascending().UnmappedType(FieldType.GeoPoint))
            .Field(f => f.Field(new Field("field1.keyword")).Descending().UnmappedType(FieldType.Keyword))
            .Field(f => f.Field(new Field("field2.sort")).Descending().UnmappedType(FieldType.Keyword))
            .Field(f => f.Field(new Field("field3")).Descending().UnmappedType(FieldType.GeoPoint))
            .Field(f => f.Field(new Field("field4")).Ascending().UnmappedType(FieldType.Long))
            .Field(f => f.Field(new Field("field5")).Ascending().UnmappedType(FieldType.Date))
            .Field(f => f.Field(new Field("field3")).Ascending().UnmappedType(FieldType.GeoPoint))
        ));

Expected behavior

Sorting should be a very common operation and easy todo.

Reference: FoundatioFx/Foundatio.Parsers#84

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

No branches or pull requests

2 participants