Skip to content

Instantly share code, notes, and snippets.

@jconwell
Created July 14, 2015 23:25
Show Gist options
  • Save jconwell/1af41535c5ecd2f4a9dd to your computer and use it in GitHub Desktop.
Save jconwell/1af41535c5ecd2f4a9dd to your computer and use it in GitHub Desktop.
Remotly Debug ElasticSearch in IntelliJ
Pretty simple once you know how.
Step 1: In IntelliJ, create a new remote debug configuration. Name it something ElasticSearchy. All of the default values should be fine. The only thing you need to change is the Host value. If ElasticSearch is gonna be running locally, just use "localhost", otherwise use the IP address of the remote machine ElasticSearch is gonna run on
Step 2: When starting ElasticSearch, just add a -D argument with the standard java remote debug values like so:
bin/elasticsearch -D "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
ElasticSearch will start and if suspend is set to 'y', it'll pause execution until you have attached the IntelliJ debugger.
Step 3: In IntilliJ, run the remote debug configuration you created in step 1.
At this point any breakpoints you have set in, say, an ElasticSearch plugin will get hit
@shreejay
Copy link

For step 2 - if using java 8, the options will be

-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

@gaurav36
Copy link

gaurav36 commented Oct 10, 2017

@jconwell
I am having issue while starting elasticsearch in debug mode

 11:55 AM Tue Oct 10# ls bin/
elasticsearch  elasticsearch-env  elasticsearch-keystore  elasticsearch-plugin  elasticsearch-translog  x-pack```

root@master /usr/share/elasticsearch :)
 11:55 AM Tue Oct 10# java -version
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-b14)
OpenJDK 64-Bit Server VM (build 25.121-b14, mixed mode)

root@master /usr/share/elasticsearch :)
 11:55 AM Tue Oct 10# bin/elasticsearch -D "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
starts elasticsearch

Option                Description                                               
------                -----------                                               
-E <KeyValuePair>     Configure a setting                                       
-V, --version         Prints elasticsearch version information and exits        
-d, --daemonize       Starts Elasticsearch in the background                    
-h, --help            show help                                                 
-p, --pidfile <Path>  Creates a pid file in the specified path on start         
-q, --quiet           Turns off standard output/error streams logging in console
-s, --silent          show minimal output                                       
-v, --verbose         show verbose output                                       
ERROR: D is not a recognized option

root@master /usr/share/elasticsearch :)
 11:55 AM Tue Oct 10# bin/elasticsearch -d "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
starts elasticsearch

Option                Description                                               
------                -----------                                               
-E <KeyValuePair>     Configure a setting                                       
-V, --version         Prints elasticsearch version information and exits        
-d, --daemonize       Starts Elasticsearch in the background                    
-h, --help            show help                                                 
-p, --pidfile <Path>  Creates a pid file in the specified path on start         
-q, --quiet           Turns off standard output/error streams logging in console
-s, --silent          show minimal output                                       
-v, --verbose         show verbose output                                       
ERROR: X is not a recognized option```

i also tried @shreejay logic for java 8

```root@master /usr/share/elasticsearch :)
 11:55 AM Tue Oct 10# bin/elasticsearch -d -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
starts elasticsearch

Option                Description                                               
 ------                -----------                                               
-E <KeyValuePair>     Configure a setting                                       
-V, --version         Prints elasticsearch version information and exits        
-d, --daemonize       Starts Elasticsearch in the background                    
-h, --help            show help                                                 
-p, --pidfile <Path>  Creates a pid file in the specified path on start         
-q, --quiet           Turns off standard output/error streams logging in console
-s, --silent          show minimal output                                       
-v, --verbose         show verbose output                                       
ERROR: a is not a recognized option```


could you point me where i am making mistake.

@bongladesch
Copy link

You have to set the ES_JAVA_OPTS variable to "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" and then starting Elasticsearch without any options or parameters.

@elbarto93
Copy link

Hi, needed to debug an elasticsearch plugin via IntelliJIDEA. (JDK 1.8, elasticsearch 5.4, Windows 10 x64)
I've managed to do it by adding -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 inside \elasticsearch-5.4.0\config\jvm.options file. I don't know why the "ES_JAVA_OPTS" method didn't work for me.
Thanks

@nikita-rastogi
Copy link

@elbarto93 , setting ES_JAVA_OPTS did not work because the value is getting set by groovy script, hence it is getting over written.
https://github.com/elastic/elasticsearch/blob/b3f3a4312b55acd02e9291d7ae231b397e275d0b/buildSrc/src/main/groovy/org/elasticsearch/gradle/test/ClusterFormationTasks.groovy#L627
i changed the port at this line and then from commandline ran ./gradlew run --debug-jvm, then the port was 5005 instead of 8000

Thanks
Nikita

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment