# Completion suggester - java API - Suggest Response\[Error: Can not write a field name, expecting a value\]

**URL:** <https://discuss.elastic.co/t/completion-suggester-java-api-suggest-response-error-can-not-write-a-field-name-expecting-a-value/13533>\
**Category:** Elasticsearch\
**Created:** [September 10, 2013, 8:56am UTC](https://discuss.elastic.co/t/completion-suggester-java-api-suggest-response-error-can-not-write-a-field-name-expecting-a-value/13533 "2013-09-10T08:56:30Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LudoN4R4](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@LudoN4R4](https://discuss.elastic.co/u/LudoN4R4)\
**Post date:** [September 10, 2013, 8:56am UTC](https://discuss.elastic.co/t/completion-suggester-java-api-suggest-response-error-can-not-write-a-field-name-expecting-a-value/13533/1 "2013-09-10T08:56:30Z")

</div>

Hello,

I try to work with the new completion suggester (0.90.3) through java API,  
but i get this error :

_Suggest Response[Error: Can not write a field name, expecting a value_]

_This a sample code that i execute :_

//client is a transport client  
client.prepareSuggest("myIndex")  
.addSuggestion(new CompletionSuggestionBuilder("")  
.field("tag")  
.text("foo")  
.size(10))  
.execute().actionGet();

If i use _"prepareSearch"_ instead of _"prepareSuggest"_ this work  
correctly (searchs results+suggestions).

Thanks in advance,

ludo.

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 10, 2013, 5:17pm UTC](https://discuss.elastic.co/t/completion-suggester-java-api-suggest-response-error-can-not-write-a-field-name-expecting-a-value/13533/2 "2013-09-10T17:17:28Z")

</div>

Could you please post the stacktrace of the error you get back? You should  
see it in the elasticsearch log too.

Thanks

On Tuesday, September 10, 2013 10:56:30 AM UTC+2, LudoN4R4 wrote:

> Hello,
> 
> I try to work with the new completion suggester (0.90.3) through java API,  
> but i get this error :
> 
> _Suggest Response[Error: Can not write a field name, expecting a value_]
> 
> _This a sample code that i execute :_
> 
> //client is a transport client  
> client.prepareSuggest("myIndex")  
> .addSuggestion(new CompletionSuggestionBuilder("")  
> .field("tag")  
> .text("foo")  
> .size(10))  
> .execute().actionGet();
> 
> If i use _"prepareSearch"_ instead of _"prepareSuggest"_ this work  
> correctly (searchs results+suggestions).
> 
> Thanks in advance,
> 
> ludo.

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![LudoN4R4](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@LudoN4R4](https://discuss.elastic.co/u/LudoN4R4)\
**Post date:** [September 10, 2013, 6:59pm UTC](https://discuss.elastic.co/t/completion-suggester-java-api-suggest-response-error-can-not-write-a-field-name-expecting-a-value/13533/3 "2013-09-10T18:59:37Z")

</div>

Sorry Luca but there are no stacktrace. I've noted that this error is not  
due to the request himself but "just" to the _"toString"_ method fromSuggestResponse[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/suggest/SuggestResponse.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/suggest/SuggestResponse.java)(which catch the error and pretty print it)

I could retrieve my "completions informations" but i've the mentionned  
error if i try to outprint directly the response object (it's not _blocking_for me).

This is my test code (_scala_):

```
*//client is a transport client*
*val* suggestResponse = client.prepareSuggest("myIndex")
                                 .addSuggestion(*new*CompletionSuggestionBuilder("test_case")
                                                      .field("tag")
                                                      .text("foo")
                                                      .size(10))
                              .execute().actionGet();

 *//print suggest response to console*
 println(suggestResponse) *// Suggest Response[Error: Can not write a 

```

field name, expecting a value]\*

```
 *// Get completion values*
 *val* it = 

```

suggestResponse.getSuggest().iterator().next().getEntries().get(0).iterator()

```
 *while* (it.hasNext()) {
    println(it.next().getText()) *// works fine print each expected 

```

fields\*  
}

On Tuesday, September 10, 2013 9:17:28 PM UTC+4, Luca Cavanna wrote:

> Could you please post the stacktrace of the error you get back? You should  
> see it in the elasticsearch log too.
> 
> Thanks
> 
> On Tuesday, September 10, 2013 10:56:30 AM UTC+2, LudoN4R4 wrote:
> 
> > Hello,
> > 
> > I try to work with the new completion suggester (0.90.3) through java  
> > API, but i get this error :
> > 
> > _Suggest Response[Error: Can not write a field name, expecting a value_]
> > 
> > _This a sample code that i execute :_
> > 
> > //client is a transport client  
> > client.prepareSuggest("myIndex")  
> > .addSuggestion(new CompletionSuggestionBuilder("")  
> > .field("tag")  
> > .text("foo")  
> > .size(10))  
> > .execute().actionGet();
> > 
> > If i use _"prepareSearch"_ instead of _"prepareSuggest"_ this work  
> > correctly (searchs results+suggestions).
> > 
> > Thanks in advance,
> > 
> > ludo.

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 10, 2013, 8:37pm UTC](https://discuss.elastic.co/t/completion-suggester-java-api-suggest-response-error-can-not-write-a-field-name-expecting-a-value/13533/4 "2013-09-10T20:37:55Z")

</div>

Hi,  
thanks to your reply I was able to understand where the problem was.  
Nothing blocking, but still a bug in the SuggestResponse#toString method,  
which was throwing that exception all the time.

I created an issue for this:  
[JsonGenerationException thrown in SuggestResponse#toString method · Issue #3661 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3661) . Just pushed a  
fix as well, it will be in the next release.

Thanks for reporting this

Cheers  
Luca

On Tue, Sep 10, 2013 at 8:59 PM, LudoN4R4 [ludon454@gmail.com](mailto:ludon454@gmail.com) wrote:

> Sorry Luca but there are no stacktrace. I've noted that this error is not  
> due to the request himself but "just" to the _"toString"_ method fromSuggestResponse[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/suggest/SuggestResponse.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/suggest/SuggestResponse.java)(which catch the error and pretty print it)
> 
> I could retrieve my "completions informations" but i've the mentionned  
> error if i try to outprint directly the response object (it's not \*  
> blocking\* for me).
> 
> This is my test code (_scala_):
> 
> ```
> *//client is a transport client*
> *val* suggestResponse = client.prepareSuggest("myIndex")
> .addSuggestion(*new*CompletionSuggestionBuilder("test_case")
> .field("tag")
> .text("foo")
> .size(10))
> .execute().actionGet();
> 
> *//print suggest response to console*
> println(suggestResponse) *// Suggest Response[Error: Can not write a
> 
> ```
> 
> field name, expecting a value]\*
> 
> ```
> *// Get completion values*
> *val* it =
> 
> ```
> 
> suggestResponse.getSuggest().iterator().next().getEntries().get(0).iterator()
> 
> ```
> *while* (it.hasNext()) {
> println(it.next().getText()) *// works fine print each expected
> 
> ```
> 
> fields\*  
> }
> 
> On Tuesday, September 10, 2013 9:17:28 PM UTC+4, Luca Cavanna wrote:
> 
> > Could you please post the stacktrace of the error you get back? You  
> > should see it in the elasticsearch log too.
> > 
> > Thanks
> > 
> > On Tuesday, September 10, 2013 10:56:30 AM UTC+2, LudoN4R4 wrote:
> > 
> > > Hello,
> > > 
> > > I try to work with the new completion suggester (0.90.3) through java  
> > > API, but i get this error :
> > > 
> > > _Suggest Response[Error: Can not write a field name, expecting a value_]
> > > 
> > > _This a sample code that i execute :_
> > > 
> > > //client is a transport client  
> > > client.prepareSuggest("**myIndex")  
> > > .addSuggestion(new CompletionSuggestionBuilder(""**)  
> > > .field("tag")  
> > > .text("foo")  
> > > .size(10))  
> > > .execute().actionGet();
> > > 
> > > If i use _"prepareSearch"_ instead of _"prepareSuggest"_ this work  
> > > correctly (searchs results+suggestions).
> > > 
> > > Thanks in advance,
> > > 
> > > ludo.
> > 
> > --  
> > You received this message because you are subscribed to a topic in the  
> > Google Groups "elasticsearch" group.  
> > To unsubscribe from this topic, visit  
> > [https://groups.google.com/d/topic/elasticsearch/FwRv0D5qIi8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/FwRv0D5qIi8/unsubscribe).  
> > To unsubscribe from this group and all its topics, send an email to  
> > [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> > For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [September 10, 2013, 9:23pm UTC](https://discuss.elastic.co/t/completion-suggester-java-api-suggest-response-error-can-not-write-a-field-name-expecting-a-value/13533/5 "2013-09-10T21:23:04Z")

</div>

Hi,  
thanks for the information you provided.  
I was able to understand where the problem was. I created the following  
issue: [JsonGenerationException thrown in SuggestResponse#toString method · Issue #3661 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3661) , and I  
pushed a fix, which will be available with next version.

Thanks for reporting this  
Luca

On Tuesday, September 10, 2013 8:59:37 PM UTC+2, LudoN4R4 wrote:

> Sorry Luca but there are no stacktrace. I've noted that this error is not  
> due to the request himself but "just" to the _"toString"_ method fromSuggestResponse[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/suggest/SuggestResponse.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/suggest/SuggestResponse.java)(which catch the error and pretty print it)
> 
> I could retrieve my "completions informations" but i've the mentionned  
> error if i try to outprint directly the response object (it's not \*  
> blocking\* for me).
> 
> This is my test code (_scala_):
> 
> ```
> *//client is a transport client*
> *val* suggestResponse = client.prepareSuggest("myIndex")
> .addSuggestion(*new*CompletionSuggestionBuilder("test_case")
> .field("tag")
> .text("foo")
> .size(10))
> .execute().actionGet();
> 
> *//print suggest response to console*
> println(suggestResponse) *// Suggest Response[Error: Can not write a 
> 
> ```
> 
> field name, expecting a value]\*
> 
> ```
> *// Get completion values*
> *val* it = 
> 
> ```
> 
> suggestResponse.getSuggest().iterator().next().getEntries().get(0).iterator()
> 
> ```
> *while* (it.hasNext()) {
> println(it.next().getText()) *// works fine print each expected 
> 
> ```
> 
> fields\*  
> }
> 
> On Tuesday, September 10, 2013 9:17:28 PM UTC+4, Luca Cavanna wrote:
> 
> > Could you please post the stacktrace of the error you get back? You  
> > should see it in the elasticsearch log too.
> > 
> > Thanks
> > 
> > On Tuesday, September 10, 2013 10:56:30 AM UTC+2, LudoN4R4 wrote:
> > 
> > > Hello,
> > > 
> > > I try to work with the new completion suggester (0.90.3) through java  
> > > API, but i get this error :
> > > 
> > > _Suggest Response[Error: Can not write a field name, expecting a value_]
> > > 
> > > _This a sample code that i execute :_
> > > 
> > > //client is a transport client  
> > > client.prepareSuggest("myIndex")  
> > > .addSuggestion(new CompletionSuggestionBuilder("")  
> > > .field("tag")  
> > > .text("foo")  
> > > .size(10))  
> > > .execute().actionGet();
> > > 
> > > If i use _"prepareSearch"_ instead of _"prepareSuggest"_ this work  
> > > correctly (searchs results+suggestions).
> > > 
> > > Thanks in advance,
> > > 
> > > ludo.

--  
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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![LudoN4R4](https://avatars.discourse-cdn.com/v4/letter/l/5fc32e/32.png) [@LudoN4R4](https://discuss.elastic.co/u/LudoN4R4)\
**Post date:** [September 11, 2013, 7:03am UTC](https://discuss.elastic.co/t/completion-suggester-java-api-suggest-response-error-can-not-write-a-field-name-expecting-a-value/13533/6 "2013-09-11T07:03:35Z")

</div>

Hi,

thanks for your reactivity.

Cordialement,  
Ludo.

On Wednesday, September 11, 2013 12:37:55 AM UTC+4, Luca Cavanna wrote:

> Hi,  
> thanks to your reply I was able to understand where the problem was.  
> Nothing blocking, but still a bug in the SuggestResponse#toString method,  
> which was throwing that exception all the time.
> 
> I created an issue for this:  
> [JsonGenerationException thrown in SuggestResponse#toString method · Issue #3661 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/3661) . Just pushed  
> a fix as well, it will be in the next release.
> 
> Thanks for reporting this
> 
> Cheers  
> Luca
> 
> On Tue, Sep 10, 2013 at 8:59 PM, LudoN4R4 \<[ludo...@gmail.com](mailto:ludo...@gmail.com) \<javascript:\>
> 
> > wrote:
> 
> > Sorry Luca but there are no stacktrace. I've noted that this error is not  
> > due to the request himself but "just" to the _"toString"_ method fromSuggestResponse[https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/suggest/SuggestResponse.java](https://github.com/elasticsearch/elasticsearch/blob/master/src/main/java/org/elasticsearch/action/suggest/SuggestResponse.java)(which catch the error and pretty print it)
> > 
> > I could retrieve my "completions informations" but i've the mentionned  
> > error if i try to outprint directly the response object (it's not \*  
> > blocking\* for me).
> > 
> > This is my test code (_scala_):
> > 
> > ```
> > *//client is a transport client*
> > *val* suggestResponse = client.prepareSuggest("myIndex")
> > .addSuggestion(*new*CompletionSuggestionBuilder("test_case")
> > .field("tag")
> > .text("foo")
> > .size(10))
> > .execute().actionGet();
> > 
> > *//print suggest response to console*
> > println(suggestResponse) *// Suggest Response[Error: Can not write 
> > 
> > ```
> > 
> > a field name, expecting a value]\*
> > 
> > ```
> > *// Get completion values*
> > *val* it = 
> > 
> > ```
> > 
> > suggestResponse.getSuggest().iterator().next().getEntries().get(0).iterator()
> > 
> > ```
> > *while* (it.hasNext()) {
> > println(it.next().getText()) *// works fine print each expected 
> > 
> > ```
> > 
> > fields\*  
> > }
> > 
> > On Tuesday, September 10, 2013 9:17:28 PM UTC+4, Luca Cavanna wrote:
> > 
> > > Could you please post the stacktrace of the error you get back? You  
> > > should see it in the elasticsearch log too.
> > > 
> > > Thanks
> > > 
> > > On Tuesday, September 10, 2013 10:56:30 AM UTC+2, LudoN4R4 wrote:
> > > 
> > > > Hello,
> > > > 
> > > > I try to work with the new completion suggester (0.90.3) through java  
> > > > API, but i get this error :
> > > > 
> > > > _Suggest Response[Error: Can not write a field name, expecting a value_  
> > > > ]
> > > > 
> > > > _This a sample code that i execute :_
> > > > 
> > > > //client is a transport client  
> > > > client.prepareSuggest("**myIndex")  
> > > > .addSuggestion(new CompletionSuggestionBuilder(""**)  
> > > > .field("tag")  
> > > > .text("foo")  
> > > > .size(10))  
> > > > .execute().actionGet();
> > > > 
> > > > If i use _"prepareSearch"_ instead of _"prepareSuggest"_ this work  
> > > > correctly (searchs results+suggestions).
> > > > 
> > > > Thanks in advance,
> > > > 
> > > > ludo.
> > > 
> > > --  
> > > You received this message because you are subscribed to a topic in the  
> > > Google Groups "elasticsearch" group.  
> > > To unsubscribe from this topic, visit  
> > > [https://groups.google.com/d/topic/elasticsearch/FwRv0D5qIi8/unsubscribe](https://groups.google.com/d/topic/elasticsearch/FwRv0D5qIi8/unsubscribe).  
> > > To unsubscribe from this group and all its topics, send an email to  
> > > [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> > > For more options, visit [https://groups.google.com/groups/opt\_out](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](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 2:17am UTC](https://discuss.elastic.co/t/completion-suggester-java-api-suggest-response-error-can-not-write-a-field-name-expecting-a-value/13533/7 "2017-07-06T02:17:11Z")

</div>


