-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
NEST/Elasticsearch.Net version:
5.2.0
Elasticsearch version:
5.2.0
json.net version
9.0.1
Description of the problem including expected versus actual behavior:
I run a query with aggregation and piped aggregation with a script.
It works fine on one field, but if i change the field i am initially aggregating against, I get the error
"An item with the same key has already been added."
I see that in the past this has been a json.net compatibility issue, however i am on 9.0.1.
I have taken the query produced by the request and run it against the ES directly and it works fine.
This works:
var searchResults =
client.Search<object>(s => s
.Size(0)
.Aggregations(
f =>
f.Terms("Truck",
t =>
t.Field("deviceId")
.Aggregations(
a =>a.Sum("Breaking Points",
sm => sm.Field("number_70035_BreakingPoints"))
.Sum("Acceleration Points",
sm => sm.Field("number_70034_AccelerationPoints"))
.BucketScript("TotalPoints",
bs =>
bs.BucketsPath(
bp =>
bp.Add("BreakingPointsSumPath",
"Breaking Points")
.Add("AccelerationPointsSumPath",
"Acceleration Points")
)
.Script(
"params.BreakingPointsSumPath+params.AccelerationPointsSumPath"))))));This does not work:
var searchResults =
client.Search<object>(s => s
.Size(0)
.Aggregations(
f =>
f.Terms("Truck",
t =>
t.Field("string_998_Driver")
.Aggregations(
a => a.Sum("Breaking Points",
sm => sm.Field("number_70035_BreakingPoints"))
.Sum("Acceleration Points",
sm => sm.Field("number_70034_AccelerationPoints"))
.BucketScript("TotalPoints",
bs =>
bs.BucketsPath(
bp =>
bp.Add("BreakingPointsSumPath",
"Breaking Points")
.Add("AccelerationPointsSumPath",
"Acceleration Points")
)
.Script(
"params.BreakingPointsSumPath+params.AccelerationPointsSumPath"))))));The only thing i changed was the top aggregation from truck to driver.
Thanks for the help!
Provide DebugInformation (if relevant):
FailureReason: Unrecoverable/Unexpected BadResponse while attempting POST http://blablabla:9200/ax/ax/_search
- [1] BadResponse: Node: http://blablabla:9200/ Exception: ArgumentException Took: 00:00:00.8928303
Audit exception in step 1 BadResponse:
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at Nest.AggregateJsonConverter.GetSubAggregates(JsonReader reader, JsonSerializer serializer) in C:\code\elasticsearch-net\src\Nest\Aggregations\AggregateJsonConverter.cs:line 434 at Nest.AggregateJsonConverter.GetKeyedBucket(JsonReader reader, JsonSerializer serializer) in C:\code\elasticsearch-net\src\Nest\Aggregations\AggregateJsonConverter.cs:line 675 at Nest.AggregateJsonConverter.ReadBucket(JsonReader reader, JsonSerializer serializer) in C:\code\elasticsearch-net\src\Nest\Aggregations\AggregateJsonConverter.cs:line 172 at Nest.AggregateJsonConverter.GetMultiBucketAggregate(JsonReader reader, JsonSerializer serializer) in C:\code\elasticsearch-net\src\Nest\Aggregations\AggregateJsonConverter.cs:line 490 at Nest.AggregateJsonConverter.ReadAggregate(JsonReader reader, JsonSerializer serializer) in C:\code\elasticsearch-net\src\Nest\Aggregations\AggregateJsonConverter.cs:line 131 at Nest.AggregateJsonConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) in C:\code\elasticsearch-net\src\Nest\Aggregations\AggregateJsonConverter.cs:line 18 at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateDictionary(IDictionary dictionary, JsonReader reader, JsonDictionaryContract contract, JsonProperty containerProperty, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader) at Nest.JsonNetSerializer.Deserialize[T](Stream stream) in C:\code\elasticsearch-net\src\Nest\CommonAbstractions\SerializationBehavior\JsonNetSerializer.cs:line 124 at Elasticsearch.Net.ResponseBuilder1.SetBody(ElasticsearchResponse1 response, Stream stream) in C:\code\elasticsearch-net\src\Elasticsearch.Net\Transport\Pipeline\ResponseBuilder.cs:line 83 at Elasticsearch.Net.ResponseBuilder1.ToResponse() in C:\code\elasticsearch-net\src\Elasticsearch.Net\Transport\Pipeline\ResponseBuilder.cs:line 37
at Elasticsearch.Net.HttpConnection.Request[TReturn](RequestData requestData) in C:\code\elasticsearch-net\src\Elasticsearch.Net\Connection\HttpConnection.cs:line 158
at Elasticsearch.Net.RequestPipeline.CallElasticsearch[TReturn](RequestData requestData) in C:\code\elasticsearch-net\src\Elasticsearch.Net\Transport\Pipeline\RequestPipeline.cs:line 413
at Elasticsearch.Net.Transport1.Request[TReturn](HttpMethod method, String path, PostData1 data, IRequestParameters requestParameters) in C:\code\elasticsearch-net\src\Elasticsearch.Net\Transport\Transport.cs:line 69
Inner Exception: An item with the same key has already been added.