How to debug Java GraphExploreRequestBuilder

Hello there.

I am writing a tool to query the Graph-API to get additional recommendations for customer choices. I wrote a function which takes some input parameters and creates a GraphExploreRequestBuilder, a Hop, a VertexRequest and more. I would like to see the JSON which is being generated and queried towards the API.

My function / class looks like this:

import org.elasticsearch.client.Client;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.xpack.graph.action.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

public class GraphQueryFactory {

    private Client client;

    public GraphExploreResponse getGraph(
            QueryBuilder queryBuilder,
            Boolean useSignificance,
            String index,
            String fieldName,
            List<String> excludes,
            int numberOfDocsPerHop,
            int sampleSize) {

        GraphExploreRequestBuilder grb =
                new GraphExploreRequestBuilder(this.client, GraphExploreAction.INSTANCE)
                        .setTypes("create-event", "order-event");

        Hop hop = grb.createNextHop(queryBuilder);

        VertexRequest vex = hop.addVertexRequest(fieldName);

        for(String exclude : excludes) {


        System.out.println("Graph query: " + grb.get());
        return grb.get();

Is there any possibility to see the actual query which is being generated? I would like to compare it to the JSON which I can see in the GUI tool in Kibana Graph under "Settings > Latest request".

Sorry, not as JSON, no.
The equivalent JSON for your request should be:

POST YOUR_INDEX/YOUR_DOC_TYPES/_xpack/_graph/_explore
  "controls": {
	"use_significance": true,
	"sample_size": YOUR_SAMPLE_SIZE
  "query": YOUR_QUERY
  "vertices": [
	  "field": "artists",
	  "exclude": [YOUR_EXCLUDES]
1 Like

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