Hi, I'm using NEST (latest version 7.0.0-alpha2) and trying to query Elasticsearch (7.0) with following:
var filters = new List<Func<QueryContainerDescriptor<MyDocument>, QueryContainer>>();
filters.Add(fq => fq.Term(t => t.Field(f => f.Status).Value("0")));//status=0
filters.Add(fq => fq.Term(t => t.Field(f => f.FreeRound).Value(false)));//freeRound = false
filters.Add(fq => fq.Term(t => t.Field(f => f.PlayerId).Value(playerId)));//playerId
filters.Add(fq => fq.DateRange(dr => dr.Field(f => f.eventTime).GreaterThanOrEquals(startDate)));//from Date
if (endDate != null)
filters.Add(fq => fq.DateRange(dr => dr.Field(f => f.eventTime)LessThanOrEquals(endDate)));//to Date
if (gameList.Count > 0)
filters.Add(fq => fq.Terms(t => t.Field(f => f.ExtGameId).Terms(gameList)));//games
try
{
var responsesResult = _client.Search<MyDocument>(s => s
.Query(q=> q
.Bool(bq => bq
.Filter(filters)
)
)
.Aggregations(a => a.Sum("sum_amount", sum => sum.Field(f => f.Amount )))
);
var sumAmount = responsesResult.Aggregations.Sum("sum_amount");
}
catch (Exception e)
{
Console.WriteLine(e);
return null;
}
But, for some reason, this fails with a message:
Elasticsearch.Net.UnexpectedElasticsearchClientException: Input string was not in a correct format. ---> System.FormatException: Input string was not in a correct format.
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
at System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
at Elasticsearch.Net.DecimalFormatter.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver )
at Elasticsearch.Net.DynamicMethodAnonymousFormatter`1.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
at Nest.SourceFormatter`1.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver )
at Elasticsearch.Net.DynamicMethodAnonymousFormatter`1.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
at Nest.ReadAsFormatter`2.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
at Elasticsearch.Net.CollectionFormatterBase`4.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver )
at Elasticsearch.Net.DynamicMethodAnonymousFormatter`1.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
at Nest.ReadAsFormatter`2.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver )
at Elasticsearch.Net.DynamicMethodAnonymousFormatter`1.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
at Elasticsearch.Net.JsonSerializer.Deserialize[T](Byte[] bytes, Int32 offset, IJsonFormatterResolver resolver)
at Elasticsearch.Net.JsonSerializer.Deserialize[T](Byte[] bytes, IJsonFormatterResolver resolver)
at Elasticsearch.Net.JsonSerializer.Deserialize[T](Stream stream, IJsonFormatterResolver resolver)
at Nest.InternalSerializer.Deserialize[T](Stream stream)
at Elasticsearch.Net.ResponseBuilder.SetBody[TResponse](ApiCallDetails details, RequestData requestData, Stream responseStream, String mimeType)
at Elasticsearch.Net.ResponseBuilder.ToResponse[TResponse](RequestData requestData, Exception ex, Nullable`1 statusCode, IEnumerable`1 warnings, Stream responseStream, String mimeType)
at Elasticsearch.Net.HttpConnection.Request[TResponse](RequestData requestData)
at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TResponse](RequestData requestData)
at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
--- End of inner exception stack trace ---
at Elasticsearch.Net.Transport`1.Request[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
at Elasticsearch.Net.ElasticLowLevelClient.DoRequest[TResponse](HttpMethod method, String path, PostData data, IRequestParameters requestParameters)
at Nest.ElasticClient.DoRequest[TRequest,TResponse](TRequest p, IRequestParameters parameters, Action`1 forceConfiguration)
at Nest.ElasticClient.Search[T,TResult](ISearchRequest request)
at Nest.ElasticClient.Search[T](ISearchRequest request)
at Nest.ElasticClient.Search[T,TResult](Func`2 selector)
at Nest.ElasticClient.Search[T](Func`2 selector)
And here are the mappings for relevant fields:
"amount": {
"type": "double"
},
"eventTime": {
"type": "date"
},
"extGameId": {
"type": "keyword"
},
"freeRound": {
"type": "boolean"
},
"playerId": {
"type": "long"
},
"status": {
"type": "keyword"
}
}
And the POCO:
[Number(NumberType.Double)]
public decimal Amount { get; set; }
[Date]
public DateTime eventTime { get; set; }
[Keyword]
public string ExtGameId { get; set; }
[Boolean]
public decimal FreeRound { get; set; }
[Number(NumberType.Long)]
public long PlayerId { get; set; }
[Keyword]
public string Status { get; set; }