Java API for Graph



Does the current Java ES 2.3 API support graph or we need to use something like JEST ?

Documentation Java API for Graph
(Mark Harwood) #2

Hi Sharad,
Below is a demo which obviously depends on core elasticsearch resources and the jar from the xpack plugin for graph:

package org.elasticsearch;

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.GraphPlugin;
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;

 * Demo graph client - find elastic meetup attendees and what other meetup groups they frequent
public class GraphDemoClient {

	public static void main(String[] args) throws Exception {
		TransportClient client = TransportClient.builder()
					.put("", "elasticsearch")			    
				.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));

		int requiredNumberOfSightings=1;
		GraphExploreRequestBuilder grb = new GraphExploreRequestBuilder(client, GraphExploreAction.INSTANCE).setIndices("meetuprsvps");
		Hop hop1 = grb.createNextHop(QueryBuilders.termQuery("_all", "elasticsearch"));
		// elasticsearch meetup attendees
		// groups attended by elastic attendees
		GraphExploreResponse response = grb.get();
		Collection<Vertex> vertices = response.getVertices();
		for (Vertex vertex : vertices) {
		for (Vertex vertex : vertices) {




Pom missing for 5.3.1 SNAPSHOT?

Hi Mark,

Can you please help me with the Maven details for the graph plugin as I couldn't find it in the maven repo?


(Mark Harwood) #4

The graph jar you need is in the graph plugin zip. This zip should be unzipped into the "plugins" directory of elasticsearch as part of installation.

(stefani hubert) #5

if you add the following repository in your pom.xml you should be able to get the dependency properly managed :

        <name>elastic plugins</name>


(David She) #6

I have trawled through the elastic site and google looking for the Java API to use for ElasticSearch Graph. I notice your snippet above but would to have a link to the documentation or a tutorial.

(Ayush Rastogi) #7

Hello Sir,
I am new in elasticSearch. I use your program for creating the graph in elasticSearch and I want to see this graph in Kibana. Can you please help me for this. and how can I use queries on this graph like - shortest path query?

(Mark Harwood) #8

Please do not hijack this Java API question with a different topic (UI questions).
I'll answer your questions here but if you want to continue the discussion please open a new question topic.

If you want to view Graphs in Kibana install the x-pack plugin and here is an example of how to configure the UI.

That would be done outside of elasticsearch/kibana currently. We are working on an export-to-GraphML feature which would allow you to use tools like Gephi which offer various Graph algos e.g. shortest-path, centrality measures, community detection etc wrapped up in a UI. If you just want to write code that does graph analysis consider using tools like Python's NetworkX library - here is an example calling the Graph API and performing betweenness centrality measures using networkX.

If you want to discuss any of the above further please open a new topic so we can keep this one focused on the Java API.

(system) #9