Analyze with custom analyzer throws JsonGenerationException

Hi

I have the same problem than the unanswered one there

Refering to the doc Java High Level REST Client, 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.

1 Like

I can totally reproduce it.

I opened

Thanks a lot for reporting this!

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.

1 Like

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