ElasticSearch Suggestion not working

Hi,

I am trying to add ElasticSearch Suggestion in my response and implementing it using SearchRequestBuilder as:-
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet(1m);

Query is correct as I tried it using kibana but Java API is showing me below error:

org.elasticsearch.ElasticsearchStatusException: {"took":23,"timed_out":false,"_shards".......................}}
at org.codelibs.elasticsearch.client.action.HttpAction.toElasticsearchException(HttpAction.java:143) ~[elasticsearch-httpclient-7.2.1.jar:?]
at org.codelibs.elasticsearch.client.action.HttpSearchAction.lambda$execute$0(HttpSearchAction.java:53) ~[elasticsearch-httpclient-7.2.1.jar:?]
at org.codelibs.curl.CurlRequest.lambda$execute$4(CurlRequest.java:202) ~[curl4j-1.2.1.jar:?]
at org.codelibs.curl.CurlRequest.lambda$connect$3(CurlRequest.java:182) ~[curl4j-1.2.1.jar:?]
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426) ~[?:?]
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) ~[?:?]
at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020) ~[?:?]
at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656) ~[?:?]
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594) ~[?:?]
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177) ~[?:?]
Suppressed: org.elasticsearch.common.xcontent.NamedObjectNotFoundException: unknown named object category [org.elasticsearch.search.suggest.Suggest$Suggestion]
	at org.elasticsearch.common.xcontent.NamedXContentRegistry.parseNamedObject(NamedXContentRegistry.java:128) ~[elasticsearch-x-content-7.2.1.jar:7.2.1]
	at org.elasticsearch.common.xcontent.support.AbstractXContentParser.namedObject(AbstractXContentParser.java:415) ~[elasticsearch-x-content-7.2.1.jar:7.2.1]
	at org.elasticsearch.common.xcontent.XContentParserUtils.parseTypedKeysObject(XContentParserUtils.java:153) ~[elasticsearch-7.2.1.jar:7.2.1]
	at org.elasticsearch.search.suggest.Suggest$Suggestion.fromXContent(Suggest.java:436) ~[elasticsearch-7.2.1.jar:7.2.1]
	at org.elasticsearch.search.suggest.Suggest.fromXContent(Suggest.java:192) ~[elasticsearch-7.2.1.jar:7.2.1]
	at org.elasticsearch.action.search.SearchResponse.innerFromXContent(SearchResponse.java:294) ~[elasticsearch-7.2.1.jar:7.2.1]
	at org.elasticsearch.action.search.SearchResponse.fromXContent(SearchResponse.java:251) ~[elasticsearch-7.2.1.jar:7.2.1]
	at org.codelibs.elasticsearch.client.action.HttpSearchAction.lambda$execute$0(HttpSearchAction.java:46) ~[elasticsearch-httpclient-7.2.1.jar:?]
	at org.codelibs.curl.CurlRequest.lambda$execute$4(CurlRequest.java:202) ~[curl4j-1.2.1.jar:?]
	at org.codelibs.curl.CurlRequest.lambda$connect$3(CurlRequest.java:182) ~[curl4j-1.2.1.jar:?]
	at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426) ~[?:?]
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) ~[?:?]
	at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020) ~[?:?]
	at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656) ~[?:?]
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594) ~[?:?]
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177) ~[?:?]
Suppressed: org.elasticsearch.common.ParsingException: Failed to parse object: expecting field with name [error] but found [took]
	at org.elasticsearch.common.xcontent.XContentParserUtils.ensureFieldName(XContentParserUtils.java:50) ~[elasticsearch-7.2.1.jar:7.2.1]
	at org.elasticsearch.ElasticsearchException.failureFromXContent(ElasticsearchException.java:587) ~[elasticsearch-7.2.1.jar:7.2.1]
	at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:169) ~[elasticsearch-7.2.1.jar:7.2.1]
	at org.codelibs.elasticsearch.client.action.HttpAction.toElasticsearchException(HttpAction.java:138) ~[elasticsearch-httpclient-7.2.1.jar:?]
	at org.codelibs.elasticsearch.client.action.HttpSearchAction.lambda$execute$0(HttpSearchAction.java:53) ~[elasticsearch-httpclient-7.2.1.jar:?]
	at org.codelibs.curl.CurlRequest.lambda$execute$4(CurlRequest.java:202) ~[curl4j-1.2.1.jar:?]
	at org.codelibs.curl.CurlRequest.lambda$connect$3(CurlRequest.java:182) ~[curl4j-1.2.1.jar:?]
	at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426) ~[?:?]
	at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) ~[?:?]
	at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020) ~[?:?]
	at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656) ~[?:?]
	at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594) ~[?:?]
	at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177) ~[?:?]

I debugged this and found that registry content for suggestion from elasticsearch-httpclient-7.2.1.jar -> org.codelibs.elasticsearch.client.HttpClient -> getDefaultNamedXContents() is commented.

    //        entries.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField(TermSuggestion.NAME),
    //                (parser, context) -> TermSuggestion.fromXContent(parser, (String) context)));
    //        entries.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField(PhraseSuggestion.NAME),
    //                (parser, context) -> PhraseSuggestion.fromXContent(parser, (String) context)));
    //        entries.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField(CompletionSuggestion.NAME),
    //                (parser, context) -> CompletionSuggestion.fromXContent(parser, (String) context)));

Why is that part commented? Is their any other jar I'll have to use? Can someone please help me with this?

Thanks,
Shweta

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