Setting up Elastic search on Windows 11 machine

I am trying to setup Elastic search on Windows 11 machine. Following instructions as outlined in:

Setup, Run & Debug Elasticsearch Source Code in IntelliJ IDEA | Elastic Blog & CONTRIBUTING.md.

After importing the project into I build the project with Build gradle in IntelliJ. After I tried to run using the command ./gradlew run --debug-jvm the process itself took more than 3hrs and threw an exception after that. Below are the details of the exception. I tried to search for answers but no luck. Really appreciate if I can get some guidance on this.

shree@Sreevardhana MINGW64 ~/repositories/elasticsearch/elasticsearch (main)
$ ./gradlew run --debug-jvm

> Configure project :modules:reindex
Disabling reindex-from-old tests because we can't get the pid file on windows

> Configure project :x-pack:qa:repository-old-versions
Disabling repository-old-versions tests because we can't get the pid file on windows
=======================================
Elasticsearch Build Hamster says Hello!
  Gradle Version        : 8.8
  OS Info               : Windows 11 10.0 (amd64)
  JDK Version           : 17.0.10+11-LTS-240 (Oracle)
  JAVA_HOME             : C:\Users\shree\Software\jdk17
  Random Testing Seed   : EA40C128BCCF3E87
  In FIPS 140 mode      : false
=======================================

> Task :x-pack:plugin:sql:sql-client:compileJava
Note: C:\Users\shree\repositories\elasticsearch\elasticsearch\x-pack\plugin\sql\sql-client\src\main\java\org\elasticsearch\xpack\sql\client\RemoteFailure.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :libs:elasticsearch-simdvec:compileMain21Java
Note: Some input files use preview features of Java SE 21.
Note: Recompile with -Xlint:preview for details.                                                                                                                                    

> Task :libs:elasticsearch-native:compileMain21Java
Note: Some input files use preview features of Java SE 21.
Note: Recompile with -Xlint:preview for details.

> Task :x-pack:plugin:security:cli:compileJava
Note: C:\Users\shree\repositories\elasticsearch\elasticsearch\x-pack\plugin\security\cli\src\main\java\org\elasticsearch\xpack\security\cli\CertificateGenerateToolProvider.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

> Task :run
Running elasticsearch in debug mode, node{::runTask-0} expecting running debug server on port 5007

> Task :run FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':run'.
> process was found dead while waiting for ports files, node{::runTask-0}

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Get more help at https://help.gradle.org.

BUILD FAILED in 3h 9m 7s
581 actionable tasks: 310 executed, 271 up-to-date
````Preformatted text`

It would be helpful to know what Elasticsearch logged. If you're running this from source, it should be in your elasticsearch directory under build/testclusters/runTask-0/logs/es.out. That may provide some more helpful context about what was happening before gradle crashed.

Kathleen Madam,

Thank you so much for your response. Please let me know if you need anything else. Setup instructions (Setup, Run & Debug Elasticsearch Source Code in IntelliJ IDEA | Elastic Blog) do not seem to be applicable in 2024. I would really appreciate if you have a document which is more current.

Below are the errors I am seeing in the es.out. The error file(hs_err_pid%p.log) mentioned is not there in the specified folder.

Thanks
Sree

java.lang.RuntimeException: starting java failed with [2]
output:
[Global flags]
ccstr ErrorFile = C:\Users\shree\repositories\elasticsearch\elasticsearch\build\testclusters\runTask-0\logs\hs_err_pid%p.log {product} {command line}

error:
WARNING: Using incubator modules: jdk.incubator.vector
ERROR: transport error 202: connect failed: Connection refused
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [s\open\src\jdk.jdwp.agent\share\native\libjdwp\debugInit.c:700]
at org.elasticsearch.server.cli.JvmOption.flagsFinal(JvmOption.java:120)
at org.elasticsearch.server.cli.JvmOption.findFinalOptions(JvmOption.java:87)
at org.elasticsearch.server.cli.MachineDependentHeap.determineHeapSettings(MachineDependentHeap.java:55)
at org.elasticsearch.server.cli.JvmOptionsParser.jvmOptions(JvmOptionsParser.java:145)
at org.elasticsearch.server.cli.JvmOptionsParser.determineJvmOptions(JvmOptionsParser.java:97)
at org.elasticsearch.server.cli.ServerCli.startServer(ServerCli.java:254)
at org.elasticsearch.server.cli.ServerCli.execute(ServerCli.java:101)
at org.elasticsearch.common.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:54)
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:94)
at org.elasticsearch.cli.Command.main(Command.java:51)
at org.elasticsearch.launcher.CliToolLauncher.main(CliToolLauncher.java:64)

Kathleen Madam,

Issue with starting elasticsearch in Debug has been resolved. I found the solution through a different post in elasticsearch posts. But still request to kindly help with the following:

a) Seeing "<============-> 99% EXECUTING [23m 38s]" in the startup logs. Does that application has started successfully.
b)When trying to Attach process getting timeout error as shown in the below logs. Am I missing any additional step.

Connected to the target VM, address: 'localhost:5007', transport: 'socket'
Disconnected from the target VM, address: 'localhost:5007', transport: 'socket'
Connected to the target VM, address: 'localhost:5007', transport: 'socket'
Disconnected from the target VM, address: 'localhost:5007', transport: 'socket'
Connected to the target VM, address: 'localhost:5007', transport: 'socket'

Connecting to Sreevardhana:60908
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:568)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:593)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:261)
at com.jetbrains.sa.SaJdwpAttachingServer.main(SaJdwpAttachingServer.java:45)
"C:\Users\shree\Software\IntelliJ IDEA Community Edition 2024.1.4\bin\launcher.exe" C:\Users\shree\Software\jdk17/bin/java --add-modules jdk.hotspot.agent --add-exports jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.runtime=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.memory=ALL-UNNAMED --add-opens jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.tools.jcore=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.classfile=ALL-UNNAMED --add-exports jdk.jdi/com.sun.tools.jdi=ALL-UNNAMED -cp "C:\Users\shree\Software\IntelliJ IDEA Community Edition 2024.1.4\plugins\java\lib\sa-jdwp.jar" com.jetbrains.sa.SaJdwpAttachingServer 10808 Sreevardhana:60908
sa-jdwp server connected
Connecting to Sreevardhana:60908
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:568)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:593)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:261)
at com.jetbrains.sa.SaJdwpAttachingServer.main(SaJdwpAttachingServer.java:45)

Correct, the blog you linked has a notification at the top of the post that indicates this is out of date for versions starting with 7.5. I would suggest looking at our CONTRIBUTING.md page for current IntelliJ setup instructions.

Try following the setup and debug instructions from the updated documentation, that may solve your issue.

Went through the CONTRIBUTING.md but unfortunately it doesn't have any additional instructions on how to run Elastic search in Debug in IntelliJ. After following some other post I was able to get Elastic search in Debug mode but facing the below issue while trying to "Attach process". Am I missing any additional steps.

Connected to the target VM, address: 'localhost:5007', transport: 'socket'
Disconnected from the target VM, address: 'localhost:5007', transport: 'socket'
Connected to the target VM, address: 'localhost:5007', transport: 'socket'
Disconnected from the target VM, address: 'localhost:5007', transport: 'socket'
Connected to the target VM, address: 'localhost:5007', transport: 'socket'

Connecting to Sreevardhana:60908
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:568)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:593)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:261)
at com.jetbrains.sa.SaJdwpAttachingServer.main(SaJdwpAttachingServer.java:45)
"C:\Users\shree\Software\IntelliJ IDEA Community Edition 2024.1.4\bin\launcher.exe" C:\Users\shree\Software\jdk17/bin/java --add-modules jdk.hotspot.agent --add-exports jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.runtime=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.memory=ALL-UNNAMED --add-opens jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.tools.jcore=ALL-UNNAMED --add-exports jdk.hotspot.agent/sun.jvm.hotspot.classfile=ALL-UNNAMED --add-exports jdk.jdi/com.sun.tools.jdi=ALL-UNNAMED -cp "C:\Users\shree\Software\IntelliJ IDEA Community Edition 2024.1.4\plugins\java\lib\sa-jdwp.jar" com.jetbrains.sa.SaJdwpAttachingServer 10808 Sreevardhana:60908
sa-jdwp server connected
Connecting to Sreevardhana:60908
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
at java.base/sun.nio.ch.Net.connect0(Native Method)
at java.base/sun.nio.ch.Net.connect(Net.java:579)
at java.base/sun.nio.ch.Net.connect(Net.java:568)
at java.base/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:593)
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
at java.base/java.net.Socket.connect(Socket.java:633)
at jdk.jdi/com.sun.tools.jdi.SocketTransportService.attach(SocketTransportService.java:261)
at com.jetbrains.sa.SaJdwpAttachingServer.main(SaJdwpAttachingServer.java:45)

OK, well in case something funny is going on with your settings, here is my Debug configuration in IntelliJ. You should have this when you import the project:

If you launch Gradle with --debug-jvm and start that Debug configuration, it should attach automatically.

Thanks for the screenshot that helped. Now I was able to start elasticsearch in Intellij in debug mode successfully.Wanted to test if the elasticsearch is running or not by executing localhost:4200 in CURL.
Getting missing authentication credentials for the REST request. Below are the error details.How do I test the running instance of elasticsearch from windows machine locally? Is it even possible. Thank you,

{"error":{"root_cause":[{"type":"security_exception","reason":"unable to authenticate user [elastic] for REST request [/]","header":{"WWW-Authenticate":["Basic realm="security" charset="UTF-8"","ApiKey"]}}],"type":"security_exception","reason":"unable to authenticate user [elastic] for REST request [/]","header":{"WWW-Authenticate":["Basic realm="security" charset="UTF-8"","ApiKey"]}},"status":401}

You want to use the credentials we specify in our CONTRIBUTING.md docs: elastic-admin:elastic-password

Thanks for your help that worked like a charm. Sorry I missed that.

Great! Happy debugging!