0.11.0 - SearchRequestBuilder.execute() throwing exception due to default content type of SMILE


(dmcclure) #1

This works fine in 0.10.0 but throws exception for any json query
string in 0.11.0:

        String jsonQuery = '{"range":{"duration": {"from":"20",

"to":"40"}}}'
def search =
node.client().prepareSearch("test").setQuery(jsonQuery.getBytes()).execute().actionGet();

In 0.10.0, call to buildAsUnsafeBytes(XContentType.JSON) is using
content type of JSON by default.
In 0.11.0, call to
sourceBuilder.buildAsUnsafeBytes(Requests.CONTENT_TYPE) is using
content type of SMILE by default.

If I set Requests.CONTENT_TYPE = XContentType.JSON before
SearchRequestBuilder.execute() call it works as expected.

Exception:
org.elasticsearch.search.builder.SearchSourceBuilderException: Failed
to build search source
at
org.elasticsearch.search.builder.SearchSourceBuilder.buildAsUnsafeBytes(SearchSourceBuilder.java:
280)
at
org.elasticsearch.action.search.SearchRequest.source(SearchRequest.java:
219)
at
org.elasticsearch.client.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:
382)
at
org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:
56)
at
org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:
51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite
$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:
229)
at
org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:
52)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:
40)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:
117)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:
121)
at
com.company.project.index.ElasticSearchSearch.executeJsonQuery(ElasticSearchSearch.groovy:
28)
at com.company.project.index.Search$executeJsonQuery.call(Unknown
Source)
at
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:
40)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:
117)
at
org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:
125)
at
com.company.project.index.ElasticSearchSearchTest.testQueries(ElasticSearchSearchTest.groovy:
68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at
com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:
108)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at
com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:
42)
at
com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:
192)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
64)
Caused by: org.elasticsearch.common.jackson.JsonGenerationException:
Can not write Binary value, expecting field name
at
org.elasticsearch.common.jackson.impl.JsonGeneratorBase._reportError(JsonGeneratorBase.java:
493)
at
org.elasticsearch.common.jackson.smile.SmileGenerator._verifyValueWrite(SmileGenerator.java:
991)
at
org.elasticsearch.common.jackson.smile.SmileGenerator.writeBinary(SmileGenerator.java:
730)
at
org.elasticsearch.common.jackson.JsonGenerator.writeBinary(JsonGenerator.java:
461)
at
org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeBinary(JsonXContentGenerator.java:
86)
at
org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:
339)
at
org.elasticsearch.search.builder.SearchSourceBuilder.toXContent(SearchSourceBuilder.java:
321)
at
org.elasticsearch.search.builder.SearchSourceBuilder.buildAsUnsafeBytes(SearchSourceBuilder.java:
277)
... 37 more


(Shay Banon) #2

Seems like there is a possible problem in the smile generator when it comes
to binary values. Will track it down.

On Thu, Sep 30, 2010 at 4:02 AM, dmcclure duane.mcclure@gmail.com wrote:

This works fine in 0.10.0 but throws exception for any json query
string in 0.11.0:

       String jsonQuery = '{"range":{"duration": {"from":"20",

"to":"40"}}}'
def search =

node.client().prepareSearch("test").setQuery(jsonQuery.getBytes()).execute().actionGet();

In 0.10.0, call to buildAsUnsafeBytes(XContentType.JSON) is using
content type of JSON by default.
In 0.11.0, call to
sourceBuilder.buildAsUnsafeBytes(Requests.CONTENT_TYPE) is using
content type of SMILE by default.

If I set Requests.CONTENT_TYPE = XContentType.JSON before
SearchRequestBuilder.execute() call it works as expected.

Exception:
org.elasticsearch.search.builder.SearchSourceBuilderException: Failed
to build search source
at

org.elasticsearch.search.builder.SearchSourceBuilder.buildAsUnsafeBytes(SearchSourceBuilder.java:
280)
at
org.elasticsearch.action.search.SearchRequest.source(SearchRequest.java:
219)
at

org.elasticsearch.client.action.search.SearchRequestBuilder.doExecute(SearchRequestBuilder.java:
382)
at

org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:
56)
at

org.elasticsearch.client.action.support.BaseRequestBuilder.execute(BaseRequestBuilder.java:
51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite
$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:
229)
at

org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:
52)
at

org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:
40)
at

org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:
117)
at

org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:
121)
at

com.company.project.index.ElasticSearchSearch.executeJsonQuery(ElasticSearchSearch.groovy:
28)
at com.company.project.index.Search$executeJsonQuery.call(Unknown
Source)
at

org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:
40)
at

org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:
117)
at

org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:
125)
at

com.company.project.index.ElasticSearchSearchTest.testQueries(ElasticSearchSearchTest.groovy:
68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:
39)
at

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at
com.intellij.junit3.JUnit3IdeaTestRunner.doRun(JUnit3IdeaTestRunner.java:
108)
at junit.textui.TestRunner.doRun(TestRunner.java:109)
at

com.intellij.junit3.JUnit3IdeaTestRunner.startRunnerWithArgs(JUnit3IdeaTestRunner.java:
42)
at

com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:
192)
at
com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:
64)
Caused by: org.elasticsearch.common.jackson.JsonGenerationException:
Can not write Binary value, expecting field name
at

org.elasticsearch.common.jackson.impl.JsonGeneratorBase._reportError(JsonGeneratorBase.java:
493)
at

org.elasticsearch.common.jackson.smile.SmileGenerator._verifyValueWrite(SmileGenerator.java:
991)
at

org.elasticsearch.common.jackson.smile.SmileGenerator.writeBinary(SmileGenerator.java:
730)
at

org.elasticsearch.common.jackson.JsonGenerator.writeBinary(JsonGenerator.java:
461)
at

org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeBinary(JsonXContentGenerator.java:
86)
at

org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:
339)
at

org.elasticsearch.search.builder.SearchSourceBuilder.toXContent(SearchSourceBuilder.java:
321)
at

org.elasticsearch.search.builder.SearchSourceBuilder.buildAsUnsafeBytes(SearchSourceBuilder.java:
277)
... 37 more


(system) #3