{"id":74207,"date":"2018-03-07T10:00:08","date_gmt":"2018-03-07T08:00:08","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=74207"},"modified":"2023-12-11T10:35:47","modified_gmt":"2023-12-11T08:35:47","slug":"elasticsearch-tutorial-beginners","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html","title":{"rendered":"ElasticSearch Tutorial for Beginners"},"content":{"rendered":"<h2>1. Introduction<\/h2>\n<p>In this example, we shall demonstrate how to make use of <a href=\"https:\/\/www.elastic.co\/\" target=\"_blank\" rel=\"noopener\">Elasticsearch<\/a>, a distributed free-text search and analysis database engine based on <a href=\"https:\/\/www.javacodegeeks.com\/2015\/09\/apache-lucene-fundamentals.html\">Apache Lucene<\/a>\u00a0with a simple <a href=\"https:\/\/www.javacodegeeks.com\/minibook\/apache-maven-cookbook\">maven<\/a>-based Java client.<\/p>\n<p>We will be using the latest version of Elasticsearch, which is ES v6.1.2\u00a0while writing this post.\u00a0For this example we use the following technologies:<\/p>\n<ul>\n<li>Maven 3<\/li>\n<li>Java 8<\/li>\n<li>Elasticsearch\u00a06.1.2<\/li>\n<\/ul>\n<p>Elasticsearch is very well known due to its capability of communication\u00a0over RESTful APIs. This means that we will be using APIs to interact with the database along with the HTTP methods like GET, POST, PUT and DELETE. It is a highly scalable\u00a0<span style=\"font-weight: 400\">distributed\u00a0<\/span>database which provides an excellent implementation with <a href=\"https:\/\/www.javacodegeeks.com\/2015\/09\/apache-lucene-fundamentals.html\" target=\"_blank\" rel=\"noopener\">Apache Lucene<\/a>. Some more features about Elasticsearch are:<\/p>\n<ul>\n<li>With the total dependency size of only around 300 KB, Elasticsearch is very lightweight<\/li>\n<li>Elasticsearch is focused solely on the performance of the queries. This means that whatever operations are done with the database, they are highly optimised and scalable<\/li>\n<li>It is a highly fault-tolerant system. If a single\u00a0Elasticsearch node dies in a cluster, the master server is very quick in identifying the issue and routes the incoming requests to a new node as fast as possible<\/li>\n<li>Elasticsearch&#8217;s speciality lies in indexable text data which can be searched on the basis of tokens and filters<\/li>\n<\/ul>\n<p>Although\u00a0Elasticsearch is a great candidate when it comes to distributed free-text search and analysis engine, it might not be the best-suited database when it comes to doing some other operations like:<\/p>\n<ul>\n<li>Counting operations like total and average<\/li>\n<li>Executing transactional queries with rollbacks<\/li>\n<li>Managing records which will be unique\u00a0across multiple given terms<\/li>\n<\/ul>\n<p>This means that\u00a0Elasticsearch is a highly use-case based database but is an excellent one when it comes to its own domains.<\/p>\n<h2>2. Prerequisites<\/h2>\n<p>You must have installed Java on your computer in order to proceed because maven is a Java tool. You can download\u00a0Java\u00a0<a href=\"http:\/\/www.oracle.com\/technetwork\/es\/java\/javase\/downloads\/index.html\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>Once you have Java installed on your system, you must install maven. You can download Maven from\u00a0<a href=\"https:\/\/maven.apache.org\/download.cgi\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/p>\n<p>Finally, you need to install Elasticsearch. You can download it from <a href=\"https:\/\/www.elastic.co\/downloads\/elasticsearch\">here<\/a> and follow the steps for your OS. Note that we will be using v6.1.2 for this lesson. Other versions might now work exactly the same way. You can verify that ES is running by opening this URL in your browser:<\/p>\n<pre class=\"brush:bash\">localhost:9200\n<\/pre>\n<p>You should get a response like:<\/p>\n<pre class=\"brush:javascript\">{\n  \"name\": \"wKUxRAO\",\n  \"cluster_name\": \"elasticsearch\",\n  \"cluster_uuid\": \"gvBXz7xsS5W4zlZuiADelw\",\n  \"version\": {\n    \"number\": \"6.1.2\",\n    \"build_hash\": \"5b1fea5\",\n    \"build_date\": \"2018-01-10T02:35:59.208Z\",\n    \"build_snapshot\": false,\n    \"lucene_version\": \"7.1.0\",\n    \"minimum_wire_compatibility_version\": \"5.6.0\",\n    \"minimum_index_compatibility_version\": \"5.0.0\"\n  },\n  \"tagline\": \"You Know, for Search\"\n}\n<\/pre>\n<p>Note that the <code>elasticsearch<\/code> is the default cluster name in Elasticsearch.<\/p>\n<h2>3. Project Setup<\/h2>\n<p>We will be using one of the many Maven archetypes to create a sample project for our example.\u00a0To create the project execute the following command in a directory that you will use as workspace:<\/p>\n<pre class=\"brush:bash\">mvn archetype:generate -DgroupId=com.javacodegeeks.example -DartifactId=jcg-elasticsearch-example -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false\n<\/pre>\n<p>If you are running maven for the first time, it will take a few seconds to accomplish the generate command because maven has to download all the required plugins and artifacts in order to make the generation task.<\/p>\n<p>Notice that now, you will have a new directory with the same name as the\u00a0<code>artifactId<\/code>\u00a0inside the chosen directory. Now, feel free to open the project in your favourite IDE.<\/p>\n<h2>4. Maven Dependencies<\/h2>\n<p>To start with, we need to add appropriate Maven dependencies to our project. We will add the following dependency to our pom.xml file:<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;properties&gt;\n  &lt;elasticsearch.version&gt;6.1.2&lt;\/elasticsearch.version&gt;\n  &lt;jackson.version&gt;2.9.4&lt;\/jackson.version&gt;\n  &lt;java.version&gt;1.8&lt;\/java.version&gt;\n&lt;\/properties&gt;\n\n&lt;dependencies&gt;\n  &lt;dependency&gt;\n    &lt;groupId&gt;org.elasticsearch&lt;\/groupId&gt;\n    &lt;artifactId&gt;elasticsearch&lt;\/artifactId&gt;\n    &lt;version&gt;${elasticsearch.version}&lt;\/version&gt;\n  &lt;\/dependency&gt;\n\n  &lt;dependency&gt;\n    &lt;groupId&gt;org.elasticsearch.client&lt;\/groupId&gt;\n    &lt;artifactId&gt;elasticsearch-rest-high-level-client&lt;\/artifactId&gt;\n    &lt;version&gt;${elasticsearch.version}&lt;\/version&gt;\n  &lt;\/dependency&gt;\n\n  &lt;dependency&gt;\n    &lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;\n    &lt;artifactId&gt;jackson-databind&lt;\/artifactId&gt;\n    &lt;version&gt;${jackson.version}&lt;\/version&gt;\n  &lt;\/dependency&gt;\n\n  &lt;dependency&gt;\n    &lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;\n    &lt;artifactId&gt;jackson-core&lt;\/artifactId&gt;\n    &lt;version&gt;${jackson.version}&lt;\/version&gt;\n  &lt;\/dependency&gt;\n\n  &lt;dependency&gt;\n    &lt;groupId&gt;junit&lt;\/groupId&gt;\n    &lt;artifactId&gt;junit&lt;\/artifactId&gt;\n    &lt;version&gt;3.8.1&lt;\/version&gt;\n    &lt;scope&gt;test&lt;\/scope&gt;\n  &lt;\/dependency&gt;\n&lt;\/dependencies&gt;\n<\/pre>\n<p>Find the latest Elasticsearch dependency <a href=\"http:\/\/search.maven.org\/#search%7Cga%7C1%7Cg%3A%22org.elasticsearch%22%20AND%20a%3A%22elasticsearch%22\">here<\/a>.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Note that we used <a href=\"https:\/\/github.com\/FasterXML\/jackson\" target=\"_blank\" rel=\"noopener\">Jackson<\/a> only as the standard JSON library for Java in our code.<\/p>\n<h2>5. Making Database Queries<\/h2>\n<p>Now, we&#8217;re ready to start building our project and add more components to it.<\/p>\n<h3>5.1 Making a Model<\/h3>\n<p>We will start by adding a very simple model in our project, a Person. Its definition will be very standard, like:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Person.java<\/em><\/span><\/p>\n<pre class=\"brush:java\">public class Person {\n\n    private String personId;\n    private String name;\n\n    \/\/standard getters and setters\n\n    @Override\n    public String toString() {\n        return String.format(\"Person{personId='%s', name='%s'}\", \n            personId, name);\n    }\n}<\/pre>\n<p>We omitted standard getters and setters for brevity but they are necessary to be made as Jackson uses them during <a href=\"https:\/\/www.javacodegeeks.com\/2013\/03\/serialization-in-java.html\" target=\"_blank\" rel=\"noopener\">Serialization<\/a> and Deserialization of an Object.<\/p>\n<h3>5.2 Defining Connection parameters<\/h3>\n<p>We will use default connection parameters for making a connection with Elasticsearch. By default, ES uses two ports: 9200 and 9201.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Connection Parameters<\/em><\/span><\/p>\n<pre class=\"brush:java\">\/\/The config parameters for the connection\nprivate static final String HOST = \"localhost\";\nprivate static final int PORT_ONE = 9200;\nprivate static final int PORT_TWO = 9201;\nprivate static final String SCHEME = \"http\";\n\nprivate static RestHighLevelClient restHighLevelClient;\nprivate static ObjectMapper objectMapper = new ObjectMapper();\n\nprivate static final String INDEX = \"persondata\";\nprivate static final String TYPE = \"person\";<\/pre>\n<p>Apart from connection configuration params, we also defined the index params above to identify where our Person data is saved.<\/p>\n<p>As mentioned in parameters above, Elasticsearch uses two ports, 9200 and 9201. The first port, <strong>9200 is used by the Elasticsearch Query Server<\/strong> with which we can query the database directly through the RESTful APIs. The second port, <strong>9201 is used by the REST server<\/strong> with which external clients can connect and perform operations.<\/p>\n<h3>5.3 Making a connection<\/h3>\n<p>We will make a method to establish the connection with the Elasticsearch Database. While making a connection to the Database, we must provide both the ports because only this way, our application will be able to connect to Elasticsearch server and we will be able to perform the database operations. Here is the code to make a connection:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Singleton method for getting Connection Object<\/em><\/span><\/p>\n<pre class=\"brush:java\">\/**\n * Implemented Singleton pattern here\n * so that there is just one connection at a time.\n * @return RestHighLevelClient\n *\/\nprivate static synchronized RestHighLevelClient makeConnection() {\n\n    if(restHighLevelClient == null) {\n        restHighLevelClient = new RestHighLevelClient(\n                RestClient.builder(\n                        new HttpHost(HOST, PORT_ONE, SCHEME),\n                        new HttpHost(HOST, PORT_TWO, SCHEME)));\n    }\n\n    return restHighLevelClient;\n}<\/pre>\n<p>Note that we have implemented <a href=\"https:\/\/www.javacodegeeks.com\/2015\/09\/singleton-design-pattern.html\" target=\"_blank\" rel=\"noopener\">Singleton Design pattern<\/a> here so that multiple connections aren&#8217;t made for ES which saves a lot of memory.<\/p>\n<p>Due to the presence of <a href=\"https:\/\/github.com\/elastic\/elasticsearch\/blob\/master\/client\/rest-high-level\/src\/main\/java\/org\/elasticsearch\/client\/RestHighLevelClient.java\" target=\"_blank\" rel=\"noopener\">RestHighLevelClient<\/a>, the connection to Elasticsearch is thread-safe. The best time to initialise this connection will be at application request or when the first request is made to the client. Once this connection client is initialised, it can be used to perform any supported APIs.<\/p>\n<h3>5.4 Closing a connection<\/h3>\n<p>Just like in older versions of Elasticsearch, we used TransportClient and we closed it once we were done with our queries, it is also necessary to close a connection once the Database interaction is complete with RestHighLevelClient as well. Here is how this can be done:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Close Connection<\/em><\/span><\/p>\n<pre class=\"brush:java\">private static synchronized void closeConnection() throws IOException {\n    restHighLevelClient.close();\n    restHighLevelClient = null;\n}<\/pre>\n<p>We assigned null to RestHighLevelClient object as well so that Singleton pattern can stay consistent.<\/p>\n<h3>5.5 Inserting Data<\/h3>\n<p>We can insert data into the\u00a0Database by converting the keys and values to a <a href=\"https:\/\/examples.javacodegeeks.com\/core-java\/maphashmap-works-internally-java\/\">Hashmap<\/a>. ES\u00a0Database only accepts values in the form of a HashMap.\u00a0Let&#8217;s see the code snippet on how this can be achieved:<\/p>\n<p><span style=\"text-decoration: underline\"><em>POST Query<\/em><\/span><\/p>\n<pre class=\"brush:java\">private static Person insertPerson(Person person){\n    person.setPersonId(UUID.randomUUID().toString());\n    Map&lt;String, Object&gt; dataMap = new HashMap&lt;String, Object&gt;();\n    dataMap.put(\"personId\", person.getPersonId());\n    dataMap.put(\"name\", person.getName());\n    IndexRequest indexRequest = new IndexRequest(INDEX, TYPE, person.getPersonId())\n            .source(dataMap);\n    try {\n        IndexResponse response = restHighLevelClient.index(indexRequest);\n    } catch(ElasticsearchException e) {\n        e.getDetailedMessage();\n    } catch (java.io.IOException ex){\n        ex.getLocalizedMessage();\n    }\n    return person;\n}<\/pre>\n<p>Above, we used Java&#8217;s <a href=\"https:\/\/examples.javacodegeeks.com\/core-java\/java-uuid-generator-example\/\" target=\"_blank\" rel=\"noopener\">UUID<\/a> class to create a unique identifier of the object as well. This way, we can control how the identifiers of an object are made.<\/p>\n<h3>5.6 Making a GET request<\/h3>\n<p>Once we are done with inserting data into the\u00a0Database, we can confirm the operation by making a GET request to the\u00a0Elasticsearch Database server. Let&#8217;s see the code snippet on how this can be done:<\/p>\n<p><span style=\"text-decoration: underline\"><em>GET Query<\/em><\/span><\/p>\n<pre class=\"brush:java\">private static Person getPersonById(String id){\n    GetRequest getPersonRequest = new GetRequest(INDEX, TYPE, id);\n    GetResponse getResponse = null;\n    try {\n        getResponse = restHighLevelClient.get(getPersonRequest);\n    } catch (java.io.IOException e){\n        e.getLocalizedMessage();\n    }\n    return getResponse != null ?\n            objectMapper.convertValue(getResponse.getSourceAsMap(), Person.class) : null;\n}<\/pre>\n<p>In this query, we just provided the main information about the object with which it can be identified, i.e., the Index, the Type and its unique identifier. Also, what we get back is actually a Map of values, as expressed by this expression:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Getting Map<\/em><\/span><\/p>\n<pre class=\"brush:java\">getResponse.getSourceAsMap()<\/pre>\n<p>It is actually the Jackson&#8217;s objectMapper which is used to convert this Map to a POJO Object which can be easily used in our program and this way, we don&#8217;t have to each key form the Map, which will be a tedious process when you can simply have a POJO object.<\/p>\n<h3>5.7 Updating Data<\/h3>\n<p>We can make an Update request to\u00a0Elasticsearch easily by first identifying the resource with its Index, Type and unique identifier. Then we can use a new HashMap object to update any number of values in the Object. Here is an example code snippet:<\/p>\n<p><span style=\"text-decoration: underline\"><em>PUT Query<\/em><\/span><\/p>\n<pre class=\"brush:java\">private static Person updatePersonById(String id, Person person){\n    UpdateRequest updateRequest = new UpdateRequest(INDEX, TYPE, id)\n            .fetchSource(true);    \/\/ Fetch Object after its update\n    try {\n        String personJson = objectMapper.writeValueAsString(person);\n        updateRequest.doc(personJson, XContentType.JSON);\n        UpdateResponse updateResponse = restHighLevelClient.update(updateRequest);\n        return objectMapper.convertValue(updateResponse.getGetResult().sourceAsMap(), Person.class);\n    }catch (JsonProcessingException e){\n        e.getMessage();\n    } catch (java.io.IOException e){\n        e.getLocalizedMessage();\n    }\n    System.out.println(\"Unable to update person\");\n    return null;\n}<\/pre>\n<p>Notice what we did above in the following statement:<\/p>\n<p><span style=\"text-decoration: underline\"><em>PUT Query<\/em><\/span><\/p>\n<pre class=\"brush:java\">updateRequest.doc(personJson, XContentType.JSON);<\/pre>\n<p>Here, we didn&#8217;t passed any specific property of the object which needs to be updated, instead, we passed complete Object JSON which will replace every key present for that Object.<\/p>\n<p>We also checked for any possible errors through the catch statements. In a real-world application, you will want to handle these errors gracefully and make documented logs.<\/p>\n<h3>5.8 Deleting Data<\/h3>\n<p>Finally, we can delete data by simply identifying the resource with its Index, Type and unique identifier.\u00a0Let&#8217;s see the code snippet on how this can be done:<\/p>\n<p><span style=\"text-decoration: underline\"><em>DELETE Query<\/em><\/span><\/p>\n<pre class=\"brush:java\">private static void deletePersonById(String id) {\n    DeleteRequest deleteRequest = new DeleteRequest(INDEX, TYPE, id);\n    try {\n        DeleteResponse deleteResponse = restHighLevelClient.delete(deleteRequest);\n    } catch (java.io.IOException e){\n        e.getLocalizedMessage();\n    }\n}<\/pre>\n<p>Again, in the DELETE Query above, we just mentioned how we can identify an object.<br \/>\n[ulp id=&#8217;lFK4fMZhpULqeQUl&#8217;]<br \/>\n&nbsp;<\/p>\n<h3>5.9 Running the application<\/h3>\n<p>Let&#8217;s try our application by performing all the operations we mentioned above. As this is a plain Java application, we will call each of these methods and print the operation results:<\/p>\n<p><span style=\"text-decoration: underline\"><em>main() method<\/em><\/span><\/p>\n<pre class=\"brush:java\">public static void main(String[] args) throws IOException {\n\n    makeConnection();\n\n    System.out.println(\"Inserting a new Person with name Shubham...\");\n    Person person = new Person();\n    person.setName(\"Shubham\");\n    person = insertPerson(person);\n    System.out.println(\"Person inserted --&gt; \" + person);\n\n    System.out.println(\"Changing name to `Shubham Aggarwal`...\");\n    person.setName(\"Shubham Aggarwal\");\n    updatePersonById(person.getPersonId(), person);\n    System.out.println(\"Person updated  --&gt; \" + person);\n\n    System.out.println(\"Getting Shubham...\");\n    Person personFromDB = getPersonById(person.getPersonId());\n    System.out.println(\"Person from DB  --&gt; \" + personFromDB);\n\n    System.out.println(\"Deleting Shubham...\");\n    deletePersonById(personFromDB.getPersonId());\n    System.out.println(\"Person Deleted\");\n\n    closeConnection();\n}<\/pre>\n<p>Once we run this application with the code, we will get the following output:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Program Output<\/em><\/span><\/p>\n<pre class=\"brush:bash\">Inserting a new Person with name Shubham...\nPerson inserted --&gt; Person{personId='bfc5ba80-832a-4925-9b8d-525a4e420cb0', name='Shubham'}\nChanging name to `Shubham Aggarwal`...\nUnable to update person\nPerson updated --&gt; Person{personId='bfc5ba80-832a-4925-9b8d-525a4e420cb0', name='Shubham Aggarwal'}\nGetting Shubham...\nPerson from DB --&gt;Person{personId='bfc5ba80-832a-4925-9b8d-525a4e420cb0', name='Shubham Aggarwal'}\nDeleting Shubham...\nPerson Deleted<\/pre>\n<p>Of course, the IDs can vary. Note that we closed the connection after we are done with the queries. This helps JVM to claim back the memory which was held by the ES connection.<\/p>\n<h2>6. Conclusion<\/h2>\n<p>In this lesson, we studied how we can use Elasticsearch along with a plain Java client which uses a <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/client\/java-rest\/current\/index.html\" target=\"_blank\" rel=\"noopener\">REST client<\/a>. Choosing to use the REST client for making it usable in a real-world application needs to be explored with a scalable example. It is a choice we need to make while we start architecting an application.<\/p>\n<p>Explore much more about Elasticsearch in our <a href=\"https:\/\/www.javacodegeeks.com\/2017\/04\/elasticsearch-tutorial-java-developers.html\">Elasticsearch course<\/a>.<\/p>\n<h2>7. Download the Complete Source Code<\/h2>\n<p>This was a tutorial on ElasticSearch REST client and queries with Java where we interacted with the\u00a0Elasticsearch Database via the RESTful operations.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2018\/03\/jcg-elasticsearch-example.zip\"><strong>Elasticsearch Example<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction In this example, we shall demonstrate how to make use of Elasticsearch, a distributed free-text search and analysis database engine based on Apache Lucene\u00a0with a simple maven-based Java client. We will be using the latest version of Elasticsearch, which is ES v6.1.2\u00a0while writing this post.\u00a0For this example we use the following technologies: Maven &hellip;<\/p>\n","protected":false},"author":20016,"featured_media":65382,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[1110,732,1201],"class_list":["post-74207","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-core-java","tag-elasticsearch","tag-enterprise-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ElasticSearch Tutorial for Beginners - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"1. Introduction In this example, we shall demonstrate how to make use of Elasticsearch, a distributed free-text search and analysis database engine based\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ElasticSearch Tutorial for Beginners - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"1. Introduction In this example, we shall demonstrate how to make use of Elasticsearch, a distributed free-text search and analysis database engine based\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2018-03-07T08:00:08+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-11T08:35:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/elastic-logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Shubham Aggarwal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Shubham Aggarwal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html\"},\"author\":{\"name\":\"Shubham Aggarwal\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0953481a8babbb7a63907edb41f357ad\"},\"headline\":\"ElasticSearch Tutorial for Beginners\",\"datePublished\":\"2018-03-07T08:00:08+00:00\",\"dateModified\":\"2023-12-11T08:35:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html\"},\"wordCount\":1509,\"commentCount\":14,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2017\\\/04\\\/elastic-logo.png\",\"keywords\":[\"Core Java\",\"Elasticsearch\",\"Enterprise Java\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html\",\"name\":\"ElasticSearch Tutorial for Beginners - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2017\\\/04\\\/elastic-logo.png\",\"datePublished\":\"2018-03-07T08:00:08+00:00\",\"dateModified\":\"2023-12-11T08:35:47+00:00\",\"description\":\"1. Introduction In this example, we shall demonstrate how to make use of Elasticsearch, a distributed free-text search and analysis database engine based\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2017\\\/04\\\/elastic-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2017\\\/04\\\/elastic-logo.png\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2018\\\/03\\\/elasticsearch-tutorial-beginners.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"ElasticSearch Tutorial for Beginners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/0953481a8babbb7a63907edb41f357ad\",\"name\":\"Shubham Aggarwal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g\",\"caption\":\"Shubham Aggarwal\"},\"description\":\"Shubham is a Java EE Engineer with about 3 years of experience in building quality products with Spring Boot, Spring Data, AWS, Kafka, PrestoDB.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sbmaggarwal\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/shubham-aggarwal\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"ElasticSearch Tutorial for Beginners - Java Code Geeks","description":"1. Introduction In this example, we shall demonstrate how to make use of Elasticsearch, a distributed free-text search and analysis database engine based","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html","og_locale":"en_US","og_type":"article","og_title":"ElasticSearch Tutorial for Beginners - Java Code Geeks","og_description":"1. Introduction In this example, we shall demonstrate how to make use of Elasticsearch, a distributed free-text search and analysis database engine based","og_url":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2018-03-07T08:00:08+00:00","article_modified_time":"2023-12-11T08:35:47+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/elastic-logo.png","type":"image\/png"}],"author":"Shubham Aggarwal","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Shubham Aggarwal","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html"},"author":{"name":"Shubham Aggarwal","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0953481a8babbb7a63907edb41f357ad"},"headline":"ElasticSearch Tutorial for Beginners","datePublished":"2018-03-07T08:00:08+00:00","dateModified":"2023-12-11T08:35:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html"},"wordCount":1509,"commentCount":14,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/elastic-logo.png","keywords":["Core Java","Elasticsearch","Enterprise Java"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html","url":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html","name":"ElasticSearch Tutorial for Beginners - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/elastic-logo.png","datePublished":"2018-03-07T08:00:08+00:00","dateModified":"2023-12-11T08:35:47+00:00","description":"1. Introduction In this example, we shall demonstrate how to make use of Elasticsearch, a distributed free-text search and analysis database engine based","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/elastic-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/elastic-logo.png","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2018\/03\/elasticsearch-tutorial-beginners.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"ElasticSearch Tutorial for Beginners"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/0953481a8babbb7a63907edb41f357ad","name":"Shubham Aggarwal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3f2c210fd210e1cafb930887d5f4c29613eb8183e62743a99e0cb93dcaec1a2b?s=96&d=mm&r=g","caption":"Shubham Aggarwal"},"description":"Shubham is a Java EE Engineer with about 3 years of experience in building quality products with Spring Boot, Spring Data, AWS, Kafka, PrestoDB.","sameAs":["https:\/\/www.linkedin.com\/in\/sbmaggarwal\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/shubham-aggarwal"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/74207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/20016"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=74207"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/74207\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/65382"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=74207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=74207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=74207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}