I am new to both Elasticsearch and Titan database and I am very much confused how do they both work and why to go for Elasticsearch.
Any explanation would be a great help.
This is not a programming question, but there is a wealth of information regarding Titan and its use of Elasticsearch in the Titan documentation.
From the architectural overview, indexes are used to speed up queries and to enable more complex queries. Titan was designed with a modular architecture so that you can decide which indexing backend to use. Titan supports 3 indexing backends: Elasticsearch, Apache Solr, and Apache Lucene.
From the indexing chapter, it tells us that in order to utilize the indexing backend, you first need to define a mixed index. Use a mixed indexes for numeric range, full-text or geo-spatial indexing. Note that this differs from a composite index which is handled by the storage backend, and composite indexes are best suited for exact match queries.
There's more to read up on in the Titan index backends documentation on how to write queries that take advantage of the indexes.