[Elasticsearch] Setup elasticsearch in IntelliJ idea

Source: Internet
Author: User
Tags git clone
Introduction


Elasticsearch is quite a cool project. This post introduces you to the setup Elasticsearch in IntelliJ idea locally. After this, we are able to:read elasticsearch source code within an IDE debug Elasticsearch Modify & Develop new FEA Tures of Elasticsearch 

Solution 

step 1



Clone the code from GitHub (Https://github.com/elastic/elasticsearch)







$> git clone git@github.com:elastic/elasticsearch.git
Step 2


Make sure your have IntelliJ idea installed locally. Now let ' s Setup elasticsearch project.



New a project from existing sources.



技术分享

Use Gradle as the package management tool. (ES 5.X, 6.X are using Gradle instead of Maven)



Check use Auto-import. The Gradle project directory should be yours accordingly. Next Click Finish.
Step 3




The Elasticsearch project might contain multiple branches. The Master branch requires latest version of Gradle, Java, etc. I Checkout to 5.6 branch, since I-environment looks good to 5.6 branch.







$> git Checkout 5.6


Have a try using the Gradle wrapper. The following would create a distribution of elasticsearch with the source code. It could take a long for downloading dependencies & building source codes (in my minutes).







./gradlew Assemble


This generates a ES distribution locally. 

Step 4



Now let's begin to run & Debug Elasticsearch source code. Directly running Elasticsearch within IntelliJ idea are possible, but requires more extra effort. Let ' s adopt elastic ' s advices. 


Run Elasticsearch



Set up a real elasticsearch instance with./gradlew Run--DEBUG-JVM







Elastic@:~/documents/elasticsearch (5.6) $./gradlew Run--DEBUG-JVM to honour "JVM settings for" Build
a new JV M'll be forked. Please consider using the daemon:https://docs.gradle.org/4.3/userguide/gradle_daemon.html.
Daemon'll be stopped in the end of the builds stopping after processing

> Configure project:benchmarks 
...note:/users/shun.ni/documents/hulu/elasticsearch/modules/transport-netty4/src/main/java/org/elasticsearch/ Http/netty4/netty4httpchannel.java uses or overrides a deprecated API.
Note:recompile with-xlint:deprecation for details.

[Elasticsearch] Listening for transport dt_socket on address:8000

> Task:d istribution:run#start Running elasticsearch in 
Deb UG mode, suspending until connected on port 8000


This is instances listens to remote IDE in a certain port:8000. Remember this port. 


Debug Elasticsearch remotely



Then use IntelliJ idea to debug this instance remotely.
Set up idea, click Run-> Edit configurations. Setup a Remote debugging.



Click OK, then we get a new icon like this.




Click Debug ' Es_remote ', then IntelliJ idea connects to ES.
Verify the Debugging



Set a breakpoint in Osinfo.java



Access The local ES Restful APIs with a browser:http://localhost:9200/_nodes this should collect all nodes ' info, and it w Ill invoke Toxcontent method in Osinfo.java. The program should is paused right at "line" (shown in the above picture).



Also the response of the RESTful API like this:






This is the start and now we are good to go. Read the source code & develop new features! Reference Https://github.com/elastic/elasticsearch/blob/master/TESTING.asciidoc#debugging-from-an-ide Contact Me



If you have any question, your are welcome to the contact me via:email:nisxiya@yeah.net Wechat:nisxiya



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.