The following section is giving an compilation error in dot net core (2.0) - vs2017, although the same is working fine in dot net 4.5.1 - vs2015.
Error in line - sortDesc = s => s.Field(f => f.Year, sort.Direction);
Error description -
SortFieldDescriptor does not contain a definition for Year. This property is present in the class VehicleItem. (same is the case with few other properties like, mileage, vehicleprice, etc, though, these are also present).
@forloop - the version of NEST is 5.5, which also installs the ElasticSearch.NET version of 5.5. The dot net version is .NET Core 2.0. (the above details are for the application where we are having issues).
The older version, where we do have the functional code are same for NEST and Elastic Search .NET except for the dot net version. Details from package.json -
package id="Elasticsearch.Net" version="5.5.0" targetFramework="net451"
package id="NEST" version="5.5.0" targetFramework="net451"
Yes, we do have the reproducible version of the error, to simulate the error.
Please refrain from posting images of code; there's no way to take that and reproduce the issue you're reporting, which only hinders the ability to help.
Can you post a minimal, complete, reproducible example that demonstrates the problem?
@forloop - it may be more appropriate at this stage, to get into an individual thread and have a discussion on the issue through screen share. Please let us know.
I have tried the same option, but the resulting expression i.e. -
sortDesc = s => s.Field((VehicleItem f) => f.Mileage, sort.Direction);
or,
sortDesc = s => s.Field((VehicleItem f) => f.Year, sort.Direction);
is giving error like -
cannot convert lambda expression to type 'Field' because it is not a delegate type.
OK. You'll need to provide a minimal, complete, reproducible example that demonstrates the problem in order to investigate further.
From the details provided, this doesn't look like an issue with NEST, more the way that it is being used. Without further details however, it's difficult to know.
Please find the minimal, complete, reproducible example as is, shown below. There is compilation error in the Class1.cs (rows 26, 29). (and I have installed NEST 5.5.0).
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
namespace NestTest
{
public class Class1
{
Func<SortDescriptor<VehicleItem>, IPromise<IList<ISort>>> GetElasticSortByField(Sorting shortR, VehicleSearch search)
{
if (shortR == null)
return null;
Func<SortDescriptor<VehicleItem>, IPromise<IList<ISort>>> sortDesc = null;
if (!string.IsNullOrEmpty(shortR.SortBy))
{
char fieldName = shortR.SortBy.ElementAt(0);
switch (fieldName)
{
case 'B':
case 'Y':
sortDesc = s => s.Field(f => f.Year, shortR.Direction);
break;
case 'P':
sortDesc = s => s.Field(f => f.VehiclePrice, shortR.Direction);
break;
case 'M':
sortDesc = s => s.Field(f => f.Mileage, shortR.Direction);
break;
case 'L':
sortDesc = s => s.GeoDistance(a => a.Field("coords").DistanceType(GeoDistanceType.Arc).Order(shortR.Direction).Unit(DistanceUnit.Miles).DistanceType(GeoDistanceType.Arc).Mode(SortMode.Min).PinTo(new Nest.GeoLocation(search.GeoLocation.Latitude, search.GeoLocation.Longitude)));
break;
default:
sortDesc = s => s.Field(f => f.Year, shortR.Direction);
break;
}
}
return sortDesc;
}
}
public class VehicleItem
{
public VehicleItem()
{
}
public short? Year { get; set; }
public int Mileage { get; set; }
public double VehiclePrice { get; set; }
public double Distance { get; set; }
public Nest.GeoLocation Coords { get; set; }
}
public class VehicleSearch
{
public Location GeoLocation { get; set; }
public Sorting Sort { get; set; }
}
public class Location
{
public int Zip { get; set; }
public int Distance { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
}
public class Sorting
{
public string SortBy { get; set; }
public SortDirection Direction { get; set; }
}
public enum SortDirection : int
{
Asc = 0,
Desc = 1,
}
}
Try to run it in the vs2017 IDE. I added a class library, this is not supposed to execute to any output. The sample code is just to demonstrate the compilation errors.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.