I use graph Java API. but I am getting the NullPointerException Errors.
This is my code ->
package org.formcept.orient;
//import java.net.InetAddress;
import java.net.InetAddress;
import java.util.Collection;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.graph.action.GraphExploreAction;
import org.elasticsearch.graph.action.GraphExploreRequestBuilder;
import org.elasticsearch.graph.action.GraphExploreResponse;
import org.elasticsearch.graph.action.Hop;
import org.elasticsearch.graph.action.Vertex;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
/**
-
Demo graph client - find elastic meetup attendees and what other meetup groups they frequent
*/
public class EsGraph {public static void main(String[] args) throws Exception {
int requiredNumberOfSightings=1; Settings settings = Settings.builder() .put("cluster.name", "elasticsearch").build(); TransportClient client1 = new PreBuiltTransportClient(settings) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300)); GraphExploreRequestBuilder grb = new GraphExploreRequestBuilder( client1, GraphExploreAction.INSTANCE).setIndices("datagraph"); Hop hop1 = grb.createNextHop(QueryBuilders.termQuery("_all", "elasticsearch")); // elasticsearch meetup attendees hop1.addVertexRequest("member_id").size(10).minDocCount(requiredNumberOfSightings); // groups attended by elastic attendees grb.createNextHop(null).addVertexRequest("group_id").size(10).minDocCount(requiredNumberOfSightings); GraphExploreResponse response = grb.get(); Collection<Vertex> vertices = response.getVertices(); System.out.println("==Members==="); for (Vertex vertex : vertices) { if(vertex.getField().equals("member_id")){ System.out.println(vertex.getTerm()); } } System.out.println("==Groups==="); for (Vertex vertex : vertices) { if(vertex.getField().equals("group_id")){ System.out.println(vertex.getTerm()); } } client1.close();
}
}
I am getting following error -:
Exception in thread "main" java.lang.NullPointerException
at org.elasticsearch.client.transport.TransportProxyClient.lambda$execute$0(TransportProxyClient.java:59)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:231)
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:345)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62)
at org.formcept.orient.EsGraph.main(EsGraph.java:42)