Graph API not working


(Ayush Rastogi) #1

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)


(Mark Harwood) #2

Let's start by making sure your data is at least there using the REST API. Can you provide the results of these calls:

curl -XGET "http://localhost:9200/meetuprsvps/_search" -d'
{
  "query": {
	"term": {
	  "_all": "elasticsearch"
	}
  }
}'

curl -XGET "http://localhost:9200/meetuprsvps/_xpack/_graph/_explore" -d'
{
  "query": {
	"term": {
	  "_all": "elasticsearch"
	}
  },
  "controls": {
	"use_significance": true,
	"sample_size": 2000
  },
  "vertices": [
	{
	  "field": "member_id"
	}
  ],
  "connections": {
	"vertices": [
	  {
		"field": "group_id"
	  }
	]
  }
}'

The second request is the equivalent of the Java example and the first is just to confirm you have an index with some data.


(Mark Harwood) #3

A full "Hello, World" example that is working for me on the latest 5.2 release: https://gist.github.com/markharwood/f9e955f52908129ef364446cfec0a65e


(system) #4

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