imotov/elasticsearch-facet-script

Not working with Java API using transport client. Hrows NullPointerException

kajal23 opened this issue · 2 comments

I am trying to use this plugin But I am having trouble using it.
It works fine with rest API /elastic search head. But When I try to execute it using Es Java API it throws null pointer exception. I am using elastic search version 0.90.0 and this plugin version 1.1.0.

Here is the exception I get

        Caused by: java.lang.NullPointerException   at org.elasticsearch.search.facet.InternalFacets.readFrom(InternalFacets.java:144)
at org.elasticsearch.search.facet.InternalFacets.readFacets(InternalFacets.java:130)
at org.elasticsearch.search.internal.InternalSearchResponse.readFrom(InternalSearchResponse.java:99)
at org.elasticsearch.search.internal.InternalSearchResponse.readInternalSearchResponse(InternalSearchResponse.java:91)
at org.elasticsearch.action.search.SearchResponse.readFrom(SearchResponse.java:219)
at org.elasticsearch.transport.netty.MessageChannelHandler.handleResponse(MessageChannelHandler.java:148)

Here is the code,
I am using elasicsearch transport client.

        SearchRequestBuilder srb = getClient().prepareSearch()
                .setSearchType(SearchType.COUNT)
                .setIndices(esConfig.getIndexName());

    srb.setExtraSource(XContentFactory.jsonBuilder().startObject()
                .startObject("facets")
                .startObject("facet1")
                .startObject("script")
                .field("init_script", "charfreq_init")
                .field("map_script", "charfreq_map")
                .field("reduce_script", "charfreq_reduce")
                .startObject("params")
                .startArray("facet")
                .endArray()
                .field("field", "DATA_ID")
                .endObject()
                .endObject()
                .endObject()
                .endObject()
                .endObject());
    response = srb.execute().actionGet();

I was debugging through it and realize it is not registering the stream for internalScriptFacet. Since its not registering it doesn't know how to read and write from the stream.
I don't know the solution though. I installed the plugin as upu suggested here I was debugging through it and realize it not registering the stream for internalScriptFacet. SInce its not registering it doesnt know how to read and write from the stream.
I don't know the solution though. I installed the plugin as you suggested here https://github.com/imotov/elasticsearch-facet-script

Yes, there are a couple of issues there. The NPE that you are getting is indeed caused by the facet not registering stream in case of the transport client. I am still trying to think of a better way to fix it, but as a work around you can try registering it manually before using the facet like this:

InternalScriptFacet.registerStreams(null, null);

The second problem was caused by the final facet serialization. It's fixed by 147d602. Please, give it a try and let me know if it works for you.