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

Nested ordering ignoring filter results #8047

Open
mitchellvanos opened this issue Feb 28, 2024 · 0 comments
Open

Nested ordering ignoring filter results #8047

mitchellvanos opened this issue Feb 28, 2024 · 0 comments
Labels
7.x Relates to a 7.x client version

Comments

@mitchellvanos
Copy link

mitchellvanos commented Feb 28, 2024

NEST/Elasticsearch.Net version:
NEST: 7.17.5

Elasticsearch version:
8.12.2

.NET runtime version:
8.0.2

Operating system version:
n/a, happens both local and on all of our cloud deployments

Description of the problem including expected versus actual behavior:

Nested ordering seems to ignore the filter when ordering the results.

Our indexed objects look something like this;

{
        "Name": "Item1",
	"SomeNestedData"{
		"SomeInnerNestedData": [
			{
				"fieldToFilterOn": 1234,
				"fieldToOrderOn": 2
			}
		]
	}
},
{
        "Name": "Item2",
	"SomeNestedData"{
		"SomeInnerNestedData": [
			{
				"fieldToFilterOn": 1234,
				"fieldToOrderOn": 1
			},
                        {
				"fieldToFilterOn": 5678,
				"fieldToOrderOn": 3
			}
		]
	}
}

Our sort descriptor looks something like this:

private static SortDescriptor<SearchItem> SortByNestedFieldValue(this SortDescriptor<SearchItem> descriptor, int filterValueToMatch)
    => descriptor
        .Field(f => f
            .Field(field => field.SomeNestedData.SomeInnerNestedData.Suffix("fieldToOrderOn"))
            .Descending()
            .Nested(n => n
                .Path(p => p.SomeNestedData)
                .Nested(n1 => n1
                    .Path(a => a.SomeNestedData.SomeInnerNestedData)
                    .Filter(filter => filter
                        .Term(f2 => f2
                            .Field(x => x.SomeNestedData.SomeInnerNestedData
                                .Suffix("fieldToFilterOn"))
                            .Value(filterValueToMatch))
                    )
                )
            )
        );

Our goal is to order everything based on the fieldToOrderOn but only if the filterValueToMatch matches our inputted value, every other fieldToOrderOn value should be ignored.

Expected Result

Given filterValueToMatch 1234 with descending ordering we expect:

  1. Item1 (orderValue 2 for 1234)
  2. Item2 (orderValue 1 for 1234)

Actual result:

  1. Item2 (orderValue 1 for 1234, but with orderValue 3 for 4567)
  2. Item1 (orderValue 2 for 1234)

Any help would be appreciated :)

@mitchellvanos mitchellvanos added the 7.x Relates to a 7.x client version label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7.x Relates to a 7.x client version
Projects
None yet
Development

No branches or pull requests

1 participant