{"action":"created","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch-net/issues/3235","repository_url":"https://api.github.com/repos/elastic/elasticsearch-net","labels_url":"https://api.github.com/repos/elastic/elasticsearch-net/issues/3235/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch-net/issues/3235/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch-net/issues/3235/events","html_url":"https://github.com/elastic/elasticsearch-net/issues/3235","id":320190686,"number":3235,"title":"Single response from array in top hits aggregation fails to deserialize","user":{"login":"carasel","id":15173537,"avatar_url":"https://avatars0.githubusercontent.com/u/15173537?v=4","gravatar_id":"","url":"https://api.github.com/users/carasel","html_url":"https://github.com/carasel","followers_url":"https://api.github.com/users/carasel/followers","following_url":"https://api.github.com/users/carasel/following{/other_user}","gists_url":"https://api.github.com/users/carasel/gists{/gist_id}","starred_url":"https://api.github.com/users/carasel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/carasel/subscriptions","organizations_url":"https://api.github.com/users/carasel/orgs","repos_url":"https://api.github.com/users/carasel/repos","events_url":"https://api.github.com/users/carasel/events{/privacy}","received_events_url":"https://api.github.com/users/carasel/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-04T08:27:16Z","updated_at":"2018-05-22T10:08:32Z","closed_at":null,"author_association":"NONE","body":"**NEST/Elasticsearch.Net version**: 5.5.0\r\n\r\n**Elasticsearch version**: 5.6.8\r\n\r\n**Description of the problem including expected versus actual behavior**:\r\nI have a top hits aggregation, which returns a single nested object. \r\n\r\n    .Aggregations(a => a\r\n                    .Nested(\"global\", gb => gb\r\n                        .Path(\"locations\")\r\n                        .Aggregations(a2 => a2\r\n                            .Terms(\"locations\", l => l\r\n                                .Field(\"locations.name.keyword\")\r\n                                .Aggregations(a3 => a3\r\n                                    .TopHits(\"locationHit\", th => th\r\n                                        .Size(1)\r\n                                    )\r\n                                )\r\n                            )\r\n                        )\r\n                    )\r\n\r\nI then try to retrieve the top hit:\r\n\r\n            var globalLocations = searchResponse.Aggs.Nested(\"global\").Terms(\"locations\");\r\n\r\n            foreach (var globalLocation in globalLocations.Buckets)\r\n            {\r\n                var locationResults = locationHit.Hits<Document>();\r\n            }\r\n\r\nThis causes the following error:\r\n\r\nCannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[MyObject+Location]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.\r\nPath 'hits[0]._source.locations.coordinates', line 1, position 589.\r\n\r\nThe json for `locationResults` is:  (locations isn't an array, though it is mapped as nested)\r\n````\r\n{{\r\n  \"_index\": \"documents\",\r\n  \"_type\": \"document\",\r\n  \"_id\": \"9cd79253703ad1b588d8bec827bc696230a4dac9\",\r\n  \"_nested\": {\r\n    \"field\": \"locations\",\r\n    \"offset\": 0\r\n  },\r\n  \"_score\": 1.0,\r\n  \"_source\": {\r\n    \"locations\": {\r\n      \"coordinates\": {\r\n        \"lat\": 37.63983154296875,\r\n        \"lon\": -123.173828125\r\n      },\r\n      \"sizeInKm\": 84.83842089198464\r\n    }\r\n  }\r\n}}\r\n````\r\n\r\nThe Location class looks like this:\r\n````\r\n        public class Location\r\n        {\r\n            public string name { get; set; }\r\n            [GeoPoint]\r\n            public GeoLocation coordinates { get; set; }\r\n            public double sizeInKm { get; set; }\r\n        }\r\n````\r\nand it is nested within a Document:\r\n````\r\n        [ElasticsearchType(Name = \"document\")]\r\n        public class Document\r\n        {\r\n            ....\r\n            [Nested]\r\n            public List<Location> locations { get; set; }\r\n            ....\r\n        }\r\n````\r\n"},"comment":{"url":"https://api.github.com/repos/elastic/elasticsearch-net/issues/comments/390936926","html_url":"https://github.com/elastic/elasticsearch-net/issues/3235#issuecomment-390936926","issue_url":"https://api.github.com/repos/elastic/elasticsearch-net/issues/3235","id":390936926,"user":{"login":"russcam","id":208231,"avatar_url":"https://avatars0.githubusercontent.com/u/208231?v=4","gravatar_id":"","url":"https://api.github.com/users/russcam","html_url":"https://github.com/russcam","followers_url":"https://api.github.com/users/russcam/followers","following_url":"https://api.github.com/users/russcam/following{/other_user}","gists_url":"https://api.github.com/users/russcam/gists{/gist_id}","starred_url":"https://api.github.com/users/russcam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/russcam/subscriptions","organizations_url":"https://api.github.com/users/russcam/orgs","repos_url":"https://api.github.com/users/russcam/repos","events_url":"https://api.github.com/users/russcam/events{/privacy}","received_events_url":"https://api.github.com/users/russcam/received_events","type":"User","site_admin":false},"created_at":"2018-05-22T10:08:32Z","updated_at":"2018-05-22T10:08:32Z","author_association":"CONTRIBUTOR","body":"@carasel would you be able to provide the complete JSON response to the request you're making (obfuscate any data that shouldn't be posted publicly)?"}}
{"actor":{"display_login":"russcam"}}