This is a C# snippet of what I am trying to do:
string MyProperty = "MyPropertyName"; var MyOrder = SortOrder.Ascending; Func<SortDescriptor<MyClass>, Nest.IPromise<IList<ISort>>> Sorting; Sorting = sort => sort .Field(so => so .Field(f => f.GetType().GetProperty(MyProperty)) .Order(MyOrder) );
MyClass is just a model for the data, so the structure is fixed for all documents.
MyProperty would be the sort column I get back from my client, it is a string and it matches exactly the property names on the C# object.
The critical point here is that I try to get the property with reflection. That doesn't seem to work. I need a way to infer the property from a string, as the frontend will provide what column of the output table it will sort by.
I looked at the docu for inference, but that seems overly complicated for this (if it even applies to that case). I don't want to remap anything, the client knows the property names from my c# object and only those are sent back as columns to sort by.
Am I doing something wrong here? It doesn't work for some reason. This snippet goes into my NEST query. It works when I just use a static property without the reflection like:
.Field(f => f.MyProperty)
I just want to use a string to identify the property, and reflection seemed to be the easiest way to do that.
I just get an "all shards failed" error from the elastic server, which isn't very helpful in figuring out what is wrong.
I am using a 7.4.1 elastic instance and the latest NEST (7.4.2).