JsonGenerationException: Can not write a field name, expecting a value

ToXContent response=///////in debugger it shows:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
////////

XContentBuilder builder=XContentFactory.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);

The last line throws the exception:

org.elasticsearch.common.jackson.core.JsonGenerationException: Can notwrite a field name
, expecting a value
at org.elasticsearch.common.jackson.core.base.GeneratorBase._reportError(
GeneratorBase.java:424)
at org.elasticsearch.common.jackson.core.json.UTF8JsonGenerator.
writeFieldName(UTF8JsonGenerator.java:189)
at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.
writeFieldName(JsonXContentGenerator.java:79)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.
java:239)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.
java:406)
at org.elasticsearch.action.search.SearchResponse.toXContent(SearchResponse
.java:249)

I'm not sure what could possibly be wrong here.

Could somebody help?

Thank you,

Eugene

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Eugene

What are you trying to achieve here?
I don't get it.

Are you trying to build your own JSon document or just want to extract information from response?

Le 4 févr. 2013 à 15:42, Eugene Strokin eugene@strokin.info a écrit :

ToXContent response=///////in debugger it shows:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
////////

XContentBuilder builder=XContentFactory.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);

The last line throws the exception:

org.elasticsearch.common.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
at org.elasticsearch.common.jackson.core.base.GeneratorBase._reportError(GeneratorBase.java:424)
at org.elasticsearch.common.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:189)
at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:79)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:239)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:406)
at org.elasticsearch.action.search.SearchResponse.toXContent(SearchResponse.java:249)

I'm not sure what could possibly be wrong here.
Could somebody help?
Thank you,
Eugene

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

All I need, is to get response from ES into some readable format. I guess
the next line of code should be something like this:

builder.string()
But I couldn't even get there because of the exception.

If there is other way reading data from response, please advice. At the
end, I need just a POJO populated with data from the response.

Thank you,

Eugene

On Monday, February 4, 2013 10:04:47 AM UTC-5, David Pilato wrote:

Hi Eugene

What are you trying to achieve here?
I don't get it.

Are you trying to build your own JSon document or just want to extract
information from response?

Le 4 févr. 2013 à 15:42, Eugene Strokin <eug...@strokin.info <javascript:>>
a écrit :

ToXContent response=///////in debugger it shows:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
////////

XContentBuilder builder=XContentFactory.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);

The last line throws the exception:

org.elasticsearch.common.jackson.core.JsonGenerationException: Can notwrite a field name
, expecting a value
at org.elasticsearch.common.jackson.core.base.GeneratorBase._reportError(
GeneratorBase.java:424)
at org.elasticsearch.common.jackson.core.json.UTF8JsonGenerator.
writeFieldName(UTF8JsonGenerator.java:189)
at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.
writeFieldName(JsonXContentGenerator.java:79)
at org.elasticsearch.common.xcontent.XContentBuilder.field(
XContentBuilder.java:239)
at org.elasticsearch.common.xcontent.XContentBuilder.field(
XContentBuilder.java:406)
at org.elasticsearch.action.search.SearchResponse.toXContent(
SearchResponse.java:249)

I'm not sure what could possibly be wrong here.

Could somebody help?

Thank you,

Eugene

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi,

please, use the Java API for ES search responses, see SearchResponse
class. You do not need to parse HTTP REST JSON by yourself.

If you feel you must fiddle with HTTP REST JSON and map it to Java
Pojos, use a JSON XContentParser. It's a oneliner and works like this

String json = ...
Map<String,Object> map =
JsonXContent.jsonXContent.createParser(json).mapAndClose();

The error ou received is a hint that you must start en empty builder
with the startObject() or startArray() method.

Jörg

Am 04.02.13 15:42, schrieb Eugene Strokin:

|
ToXContentresponse=///////in debugger it shows:
{
"took":3,
"timed_out":false,
"_shards":{
"total":5,
"successful":5,
"failed":0
},
"hits":{
"total":0,
"max_score":null,
"hits":[]
}
}
////////

XContentBuilderbuilder=XContentFactory.contentBuilder(XContentType.JSON);
response.toXContent(builder,ToXContent.EMPTY_PARAMS);
|

The last line throws the exception:

|
org.elasticsearch.common.jackson.core.JsonGenerationException:Cannotwrite
a field name,expecting a value
at
org.elasticsearch.common.jackson.core.base.GeneratorBase._reportError(GeneratorBase.java:424)
at
org.elasticsearch.common.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:189)
at
org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:79)
at
org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:239)
at
org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:406)
at
org.elasticsearch.action.search.SearchResponse.toXContent(SearchResponse.java:249)
|

I'm not sure what could possibly be wrong here.

Could somebody help?

Thank you,

Eugene

--
You received this message because you are subscribed to the Google
Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send
an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Here is an example on how I proceed to read back hits and convert them to beans: https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267

HTH
David.

Le 4 févr. 2013 à 16:13, Eugene Strokin eugene@strokin.info a écrit :

All I need, is to get response from ES into some readable format. I guess the next line of code should be something like this:

builder.string()
But I couldn't even get there because of the exception.

If there is other way reading data from response, please advice. At the end, I need just a POJO populated with data from the response.
Thank you,
Eugene

On Monday, February 4, 2013 10:04:47 AM UTC-5, David Pilato wrote:
Hi Eugene

What are you trying to achieve here?
I don't get it.

Are you trying to build your own JSon document or just want to extract information from response?

Le 4 févr. 2013 à 15:42, Eugene Strokin eug...@strokin.info a écrit :

ToXContent response=///////in debugger it shows:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
////////

XContentBuilder builder=XContentFactory.contentBuilder(XContentType.JSON);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);

The last line throws the exception:

org.elasticsearch.common.jackson.core.JsonGenerationException: Can not write a field name, expecting a value
at org.elasticsearch.common.jackson.core.base.GeneratorBase._reportError(GeneratorBase.java:424)
at org.elasticsearch.common.jackson.core.json.UTF8JsonGenerator.writeFieldName(UTF8JsonGenerator.java:189)
at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeFieldName(JsonXContentGenerator.java:79)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:239)
at org.elasticsearch.common.xcontent.XContentBuilder.field(XContentBuilder.java:406)
at org.elasticsearch.action.search.SearchResponse.toXContent(SearchResponse.java:249)

I'm not sure what could possibly be wrong here.
Could somebody help?
Thank you,
Eugene

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

This is exactly what I need. Thank you David.

I've shared an Utility for populating data from ES responses and generating
ES source for indexing.
May be it would help someone:

On Monday, February 4, 2013 10:38:40 AM UTC-5, David Pilato wrote:

Here is an example on how I proceed to read back hits and convert them to
beans:
https://github.com/elasticsearchfr/hands-on/blob/answers/src/test/java/org/elasticsearchfr/handson/ex2/SearchTest.java#L267

HTH
David.

Le 4 févr. 2013 à 16:13, Eugene Strokin <eug...@strokin.info <javascript:>>
a écrit :

All I need, is to get response from ES into some readable format. I guess
the next line of code should be something like this:

builder.string()
But I couldn't even get there because of the exception.

If there is other way reading data from response, please advice. At the
end, I need just a POJO populated with data from the response.

Thank you,

Eugene

On Monday, February 4, 2013 10:04:47 AM UTC-5, David Pilato wrote:

Hi Eugene

What are you trying to achieve here?
I don't get it.

Are you trying to build your own JSon document or just want to extract
information from response?

Le 4 févr. 2013 à 15:42, Eugene Strokin eug...@strokin.info a écrit :

ToXContent response=///////in debugger it shows:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
////////

XContentBuilder builder=XContentFactory.contentBuilder(XContentType.JSON
);
response.toXContent(builder, ToXContent.EMPTY_PARAMS);

The last line throws the exception:

org.elasticsearch.common.jackson.core.JsonGenerationException: Can notwrite a field name
, expecting a value
at org.elasticsearch.common.jackson.core.base.GeneratorBase._reportError
(GeneratorBase.java:424)
at org.elasticsearch.common.jackson.core.json.UTF8JsonGenerator.
writeFieldName(UTF8JsonGenerator.java:189)
at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.
writeFieldName(JsonXContentGenerator.java:79)
at org.elasticsearch.common.xcontent.XContentBuilder.field(
XContentBuilder.java:239)
at org.elasticsearch.common.xcontent.XContentBuilder.field(
XContentBuilder.java:406)
at org.elasticsearch.action.search.SearchResponse.toXContent(
SearchResponse.java:249)

I'm not sure what could possibly be wrong here.

Could somebody help?

Thank you,

Eugene

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearc...@googlegroups.com <javascript:>.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.