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
@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