ElasticSearch is implemented in Java language. So, we need build and debug tools in Java language. I show build and debug procedures using Java build tool Gradle and Java integrated development environment Intellij IDEA.
1. Prerequisites
Version of Elasticsearch: Elasticsearch 7.10
Target Machine and Host Machine: Windows10(same machine)
2. Building Elasticsearch
Installi Gradle which is a Java build tool.
(1) Install Oracle JDK11 from the following link
https://www.oracle.com/java/technologies/javase-downloads.html
(2) Install Gradle according to the following link procedures
https://gradle.org/install/
(3) Download ElasticSearch sources from the following link. Hereinafter we call the directory whch download to <top>.
https://github.com/elastic/elasticsearch
(4) Execute the following command to build Elasticsearch at commandline with working directory <top>
gradlew.bat localDistro
3. Debugging Elasticsearch
(1) Install Java integrated development environment IntelliJ IDEA community edition from the following link
https://www.jetbrains.com/idea/download/#section=windows
(2) Open ElasticSsearch project using Intellij IDEA selecting <top>
(3) Select [Run]>[Debug Elasticsearch] in Intellij IDEA
(4) Execute the following comannd at commandline with working directory <top>
gradlew.bat run –debug-jvm
(5) Install curl
(6) Create a breakpoint at validate() method of IndexRequest class in <top>/server/src/main/java/org/elasticsearch/action/index/IndexRequest.java
(7) Execute the following comannd at commandline.
curl -X POST “http://elastic:password@localhost:9200/my-index-000001/_doc?pretty” -H “Content-Type: application/json” -d “{\”title\”: \”test document\”}”
(8) If you see that Elasticsearch stops at (6) breakpoint, your Debugging insert command successes.
(9) Create a breakpoint at start() method of AbstractSearchAsyncAction class in <top>/server/src/main/java/org/elasticsearch/action/search/AbstractSearchAsyncAction.java
(10) Execute the following comannd at commandline.
curl -X POST “http://elastic:password@localhost:9200/my-index-000001/_doc?pretty” -H “Content-Type: application/json” -d “{\”title\”: \”test document\”}”
(11) If you see that Elasticsearch stops at (9) breakpoint, your Debugging search command successes.
4. References
[1] Contributing to elasticsearch
https://github.com/elastic/elasticsearch/blob/master/CONTRIBUTING.md