elasticsearch codebase is hosted on github, and its just a fork away. To get started with the code, start by either forking or cloning the repo. One can also just download the master code in either zip or tar.gz.
Once downloaded, building an elasticsearch distribution is simple. From within the source, run:
$ ./gradlew
If you are running it for the first time, go get a cup of coffee (or better yet, a beer), it will take some time to download all the dependencies elasticsearch has. Once finished, a full distribution of the elasticsearch will be created under build/distributions.
In order to use it, just get either the zip or tar.gz installation, extract it, and fire up elasticsearch -f. You now have a fully functional master based elasticsearch version running.
elasticsearch comes with built in IntelliJ IDEA project files. Just download the community edition, fire it up, and import the project.
In order to get all the dependencies right, you will need to run gradle and also gradle test once to download all the dependencies.