# Analyze with custom analyzer throws JsonGenerationException

**URL:** https://discuss.elastic.co/t/analyze-with-custom-analyzer-throws-jsongenerationexception/170644
**Category:** Elasticsearch
**Created:** [March 3, 2019, 4:05pm UTC](https://discuss.elastic.co/t/analyze-with-custom-analyzer-throws-jsongenerationexception/170644 "2019-03-03T16:05:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mmarie](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mmarie](https://discuss.elastic.co/u/mmarie)
#### Post date: [March 3, 2019, 4:05pm UTC](https://discuss.elastic.co/t/analyze-with-custom-analyzer-throws-jsongenerationexception/170644/1 "2019-03-03T16:05:48Z")

</div>

Hi

I have the same problem than the unanswered one [there](https://discuss.elastic.co/t/invoke-java-high-level-rest-client-analyzer-api-issue/161276)

Refering to the doc [Java High Level REST Client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/6.6/java-rest-high-analyze.html), I built a custom analyzer

```
AnalyzeRequest request = new AnalyzeRequest();
request.text("<b>Some text to analyze</b>");
request.addCharFilter("html_strip");                
request.tokenizer("standard");                      
request.addTokenFilter("lowercase");

```

Though, when I run the anayze

`client.indices().analyze(analyzeRequest, RequestOptions.DEFAULT)`

I get the following exception:

```
Exception in thread "main" com.fasterxml.jackson.core.JsonGenerationException: Can not write a string, expecting field name (context: Object)
	at com.fasterxml.jackson.core.JsonGenerator._reportError(JsonGenerator.java:1897)
	at com.fasterxml.jackson.core.json.JsonGeneratorImpl._reportCantWriteValueExpectName(JsonGeneratorImpl.java:244)
	at com.fasterxml.jackson.core.json.UTF8JsonGenerator._verifyValueWrite(UTF8JsonGenerator.java:1033)
	at com.fasterxml.jackson.core.json.UTF8JsonGenerator.writeString(UTF8JsonGenerator.java:442)
	at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.writeString(JsonXContentGenerator.java:281)
	at org.elasticsearch.common.xcontent.XContentBuilder.value(XContentBuilder.java:660)
	at org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest$NameOrDefinition.toXContent(AnalyzeRequest.java:111)
	at org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest.toXContent(AnalyzeRequest.java:284)
	at org.elasticsearch.common.xcontent.XContentHelper.toXContent(XContentHelper.java:353)
	at org.elasticsearch.client.RequestConverters.createEntity(RequestConverters.java:676)
	at org.elasticsearch.client.RequestConverters.createEntity(RequestConverters.java:671)
	at org.elasticsearch.client.IndicesRequestConverters.analyze(IndicesRequestConverters.java:422)
	at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1758)
	at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1732)
	at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1694)
	at org.elasticsearch.client.IndicesClient.analyze(IndicesClient.java:1285)
	at es.Exploration$.getAnalyzeOnTheFly(Exploration.scala:197)
	at es.Exploration$.main(Exploration.scala:238)
	at es.Exploration.main(Exploration.scala)
	Suppressed: java.lang.IllegalStateException: Failed to close the XContentBuilder
		at org.elasticsearch.common.xcontent.XContentBuilder.close(XContentBuilder.java:1002)
		at org.elasticsearch.common.xcontent.XContentHelper.toXContent(XContentHelper.java:348)
		... 10 more
	Caused by: java.io.IOException: Unclosed object or array found
		at org.elasticsearch.common.xcontent.json.JsonXContentGenerator.close(JsonXContentGenerator.java:469)
		at org.elasticsearch.common.xcontent.XContentBuilder.close(XContentBuilder.java:1000)
		... 11 more

```

Everything works well if I use a built-in analyzer.

Thanks in advance for your anwser,  
M.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [March 4, 2019, 9:27pm UTC](https://discuss.elastic.co/t/analyze-with-custom-analyzer-throws-jsongenerationexception/170644/2 "2019-03-04T21:27:00Z")

</div>

I can totally reproduce it.

I opened

> <https://github.com/elastic/elasticsearch/issues/39670>

Thanks a lot for reporting this!

---

<div class="post-metadata">

### Author: ![mmarie](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mmarie](https://discuss.elastic.co/u/mmarie)
#### Post date: [March 13, 2019, 7:52am UTC](https://discuss.elastic.co/t/analyze-with-custom-analyzer-throws-jsongenerationexception/170644/3 "2019-03-13T07:52:17Z")

</div>

You'r welcome!

For thoses interested by analyse on the fly, I overcomed the current limitation using an analyzer defined in an index I first put in ES with the custom analyzer I needed.  
This as proposed in the same doc section.

---

<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: [April 10, 2019, 7:52am UTC](https://discuss.elastic.co/t/analyze-with-custom-analyzer-throws-jsongenerationexception/170644/4 "2019-04-10T07:52:34Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
