{"action":"opened","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch/issues/36474","repository_url":"https://api.github.com/repos/elastic/elasticsearch","labels_url":"https://api.github.com/repos/elastic/elasticsearch/issues/36474/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/36474/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/36474/events","html_url":"https://github.com/elastic/elasticsearch/issues/36474","id":389713867,"node_id":"MDU6SXNzdWUzODk3MTM4Njc=","number":36474,"title":"Unable to use WeightedAvg aggregation with Rest High Level Client","user":{"login":"tke","id":224875,"node_id":"MDQ6VXNlcjIyNDg3NQ==","avatar_url":"https://avatars1.githubusercontent.com/u/224875?v=4","gravatar_id":"","url":"https://api.github.com/users/tke","html_url":"https://github.com/tke","followers_url":"https://api.github.com/users/tke/followers","following_url":"https://api.github.com/users/tke/following{/other_user}","gists_url":"https://api.github.com/users/tke/gists{/gist_id}","starred_url":"https://api.github.com/users/tke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tke/subscriptions","organizations_url":"https://api.github.com/users/tke/orgs","repos_url":"https://api.github.com/users/tke/repos","events_url":"https://api.github.com/users/tke/events{/privacy}","received_events_url":"https://api.github.com/users/tke/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-12-11T11:16:31Z","updated_at":"2018-12-11T11:16:31Z","closed_at":null,"author_association":"NONE","body":"<!--\r\n\r\n** Please read the guidelines below. **\r\n\r\nIssues that do not follow these guidelines are likely to be closed.\r\n\r\n1.  GitHub is reserved for bug reports and feature requests. The best place to\r\n    ask a general question is at the Elastic [forums](https://discuss.elastic.co).\r\n    GitHub is not the place for general questions.\r\n\r\n2.  Is this bug report or feature request for a supported OS? If not, it\r\n    is likely to be closed.  See https://www.elastic.co/support/matrix#show_os\r\n\r\n3.  Please fill out EITHER the feature request block or the bug report block\r\n    below, and delete the other block.\r\n\r\n-->\r\n\r\n<!-- Bug report -->\r\n\r\n**Elasticsearch version** (`bin/elasticsearch --version`): \r\n6.5.2\r\n\r\n**Plugins installed**:\r\nN/A\r\n\r\n**JVM version** (`java -version`):\r\n1.8.0_172\r\n\r\n**OS version** (`uname -a` if on a Unix-like system):\r\nLinux 4.15.0-34-generic #37-Ubuntu SMP Mon Aug 27 15:21:48 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux\r\n\r\n**Description of the problem including expected versus actual behavior**:\r\nAdding a weighted_avg aggregation to a search source results in an exception when marshalling the source:\r\n`com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value`\r\n\r\n**Steps to reproduce**:\r\n\r\nA minimal test case (based on the example `weighted_avg` usage in the documentation) for this is as follows:\r\n```java\r\nimport org.elasticsearch.search.aggregations.AggregationBuilders;\r\nimport org.elasticsearch.search.aggregations.support.MultiValuesSourceFieldConfig;\r\nimport org.elasticsearch.search.builder.SearchSourceBuilder;\r\nimport org.json.JSONException;\r\nimport org.junit.jupiter.api.Test;\r\nimport org.skyscreamer.jsonassert.JSONAssert;\r\nimport org.skyscreamer.jsonassert.JSONCompareMode;\r\n\r\npublic class TestCase {\r\n    @Test\r\n    public void weightedAverageSerialization() throws JSONException {\r\n        SearchSourceBuilder sourceBuilder = new SearchSourceBuilder()\r\n                .size(0)\r\n                .aggregation(\r\n                        AggregationBuilders.weightedAvg(\"weighted_grade\")\r\n                                .value(new MultiValuesSourceFieldConfig.Builder()\r\n                                        .setFieldName(\"grade\")\r\n                                        .build())\r\n                                .weight(new MultiValuesSourceFieldConfig.Builder()\r\n                                        .setFieldName(\"weight\")\r\n                                        .build())\r\n                );\r\n\r\n        String actualStr = sourceBuilder.toString();\r\n        JSONAssert.assertEquals(\"{\\n\" +\r\n                \"  \\\"size\\\": 0,\\n\" +\r\n                \"  \\\"aggregations\\\" : {\\n\" +\r\n                \"    \\\"weighted_grade\\\": {\\n\" +\r\n                \"      \\\"weighted_avg\\\": {\\n\" +\r\n                \"        \\\"value\\\": {\\n\" +\r\n                \"          \\\"field\\\": \\\"grade\\\"\\n\" +\r\n                \"        },\\n\" +\r\n                \"        \\\"weight\\\": {\\n\" +\r\n                \"          \\\"field\\\": \\\"weight\\\"\\n\" +\r\n                \"        }\\n\" +\r\n                \"      }\\n\" +\r\n                \"    }\\n\" +\r\n                \"  }\\n\" +\r\n                \"}\", actualStr, JSONCompareMode.LENIENT);\r\n    }\r\n}\r\n```\r\n\r\n**Provide logs (if relevant)**:\r\n```\r\nElasticsearchException[com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value\r\n]; nested: JsonGenerationException[Can not write a field name, expecting a value];\r\n\tat org.elasticsearch.search.builder.SearchSourceBuilder.toString(SearchSourceBuilder.java:1565)\r\n\tat org.elasticsearch.search.builder.SearchSourceBuilder.toString(SearchSourceBuilder.java:1558)\r\n\tat TestCase.weightedAverageSerialization(TestCase.java:24)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\r\n\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\r\n\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\r\n\tat java.lang.reflect.Method.invoke(Method.java:498)\r\n\tat org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:515)\r\n\tat org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:115)\r\n\tat org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:171)\r\n\tat org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)\r\n\tat org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:167)\r\n\tat org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:114)\r\n\tat org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:59)\r\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:105)\r\n\tat org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)\r\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:95)\r\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:71)\r\n\tat java.util.ArrayList.forEach(ArrayList.java:1257)\r\n\tat org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)\r\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:110)\r\n\tat org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)\r\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:95)\r\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:71)\r\n\tat java.util.ArrayList.forEach(ArrayList.java:1257)\r\n\tat org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)\r\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:110)\r\n\tat org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:72)\r\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:95)\r\n\tat org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:71)\r\n\tat org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)\r\n\tat org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)\r\n\tat org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)\r\n\tat org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:220)\r\n\tat org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:188)\r\n\tat org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:202)\r\n\tat org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:181)\r\n\tat org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128)\r\n\tat com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:74)\r\n\tat com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)\r\n\tat com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)\r\n\tat com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)\r\nCaused by: com.fasterxml.jackson.core.JsonGenerationException: Can not write a field name, expecting a value\r\n\tat com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:1961)\r\n\tat com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:188)\r\n\tat com.fasterxml.jackson.core.json.JsonGeneratorImpl.writeStringField(JsonGeneratorImpl.java:202)\r\n\tat org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeStringField(JsonXContentGenerator.java:276)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:636)\r\n\tat org.elasticsearch.search.aggregations.support.MultiValuesSourceFieldConfig.toXContent(MultiValuesSourceFieldConfig.java:120)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:857)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:850)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:828)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.map(XContentBuilder.java:888)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.unknownValue(XContentBuilder.java:822)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:804)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:789)\r\n\tat org.elasticsearch.search.aggregations.support.MultiValuesSourceAggregationBuilder.internalXContent(MultiValuesSourceAggregationBuilder.java:228)\r\n\tat org.elasticsearch.search.aggregations.AbstractAggregationBuilder.toXContent(AbstractAggregationBuilder.java:154)\r\n\tat org.elasticsearch.search.aggregations.AggregatorFactories$Builder.toXContent(AggregatorFactories.java:448)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:857)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:850)\r\n\tat org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:842)\r\n\tat org.elasticsearch.search.builder.SearchSourceBuilder.innerToXContent(SearchSourceBuilder.java:1269)\r\n\tat org.elasticsearch.search.builder.SearchSourceBuilder.toXContent(SearchSourceBuilder.java:1309)\r\n\tat org.elasticsearch.common.xcontent.XContentHelper.toXContent(XContentHelper.java:349)\r\n\tat org.elasticsearch.search.builder.SearchSourceBuilder.toString(SearchSourceBuilder.java:1563)\r\n\t... 41 more\r\n\tSuppressed: java.lang.IllegalStateException: Failed to close the XContentBuilder\r\n\t\tat org.elasticsearch.common.xcontent.XContentBuilder.close(XContentBuilder.java:1002)\r\n\t\tat org.elasticsearch.common.xcontent.XContentHelper.toXContent(XContentHelper.java:344)\r\n\t\t... 42 more\r\n\tCaused by: java.io.IOException: Unclosed object or array found\r\n\t\tat org.elasticsearch.common.xcontent.json.JsonXContentGenerator.close(JsonXContentGenerator.java:469)\r\n\t\tat org.elasticsearch.common.xcontent.XContentBuilder.close(XContentBuilder.java:1000)\r\n\t\t... 43 more\r\n```\r\n"}}
{"actor":{"display_login":"tke"}}