{"id":64095,"date":"2017-02-27T19:00:06","date_gmt":"2017-02-27T17:00:06","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/?p=64095"},"modified":"2023-12-11T10:15:30","modified_gmt":"2023-12-11T08:15:30","slug":"elasticsearch-java-developers-elasticsearch-command-line","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html","title":{"rendered":"Elasticsearch for Java Developers: Elasticsearch from the command line"},"content":{"rendered":"<p><em>This article is part of our Academy Course titled <a href=\"https:\/\/www.javacodegeeks.com\/2017\/04\/elasticsearch-tutorial-java-developers.html\">Elasticsearch Tutorial for Java Developers<\/a>.<\/p>\n<p>In this course, we provide a series of tutorials so that you can develop your own Elasticsearch based applications. We cover a wide range of topics, from installation and operations, to Java API Integration and reporting. With our straightforward tutorials, you will be able to get your own projects up and running in minimum time. Check it out <a href=\"https:\/\/www.javacodegeeks.com\/2017\/04\/elasticsearch-tutorial-java-developers.html\">here<\/a>!<\/em><\/p>\n<h2><a name=\"introduction\"><\/a>1. Introduction<\/h2>\n<p><a href=\"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-introduction.html\">From the previous part of the tutorial<\/a> we have got a pretty good understanding of what <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> is, its basic concepts and the power of search capabilities it could bring to our applications. In this section we are jumping right into the battle and going to apply our knowledge in practice. Along this section <a href=\"https:\/\/curl.haxx.se\/\">curl<\/a> and\/or <a href=\"https:\/\/httpie.org\/\">http<\/a> would be the only tools we are going to use to make friends with <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a>.<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#healthy\">2. Is My Cluster Healthy?<\/a><\/dt>\n<dt><a href=\"#indices\">3. All About Indices<\/a><\/dt>\n<dt><a href=\"#documents\">4. Documents, More Documents, \u2026<\/a><\/dt>\n<dt><a href=\"#mapping\">5. What if My Mapping Types Are Suboptimal<\/a><\/dt>\n<dt><a href=\"#search\">6. The Search Time<\/a><\/dt>\n<dt><a href=\"#mutations\">7. Mutations by Query<\/a><\/dt>\n<dt><a href=\"#queries\">8. Know Your Queries Better<\/a><\/dt>\n<dt><a href=\"#insights\">9. From Search to Insights<\/a><\/dt>\n<dt><a href=\"#breathing\">10. Watch Your Cluster Breathing<\/a><\/dt>\n<dt><a href=\"#conclusions\">11. Conclusions<\/a><\/dt>\n<dt><a href=\"#next\">12. What\u2019s next<\/a><\/dt>\n<\/dl>\n<\/div>\n<p>To sum up, we have already finalized our book <code>catalog<\/code> index and mapping types so we are going to pick it up from there. In order to keep things as close to reality as possible, we are going to use <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> cluster with three nodes (all run as <a href=\"https:\/\/www.docker.com\/\">Docker<\/a> containers), while <code>catalog<\/code> index is going to be configured with replication factor of two.<\/p>\n<p>As we are going to see, working with <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> cluster has quite a few subtleties comparing to standalone instance and it is better to be prepared to deal with them. Hopefully, you still remember from the previous part of the tutorial how to start <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> as this is going to be the only prerequisite: having the cluster up and running. With that, let us get started!<\/p>\n<h2><a name=\"healthy\"><\/a>2. Is My Cluster Healthy?<\/h2>\n<p>The first thing you would need to know about your <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> cluster before doing anything with it is its health. There are a couple of ways to gather this information but arguably the easiest and most convenient one is by using <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/cluster.html\">Cluster APIs<\/a>, particularly <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/cluster-health.html\">cluster health endpoint<\/a>.<\/p>\n<pre class=\"brush:bash\">$ http http:\/\/localhost:9200\/_cluster\/health\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"active_primary_shards\": 0,\n    \"active_shards\": 0,\n    \"active_shards_percent_as_number\": 100.0,\n    \"cluster_name\": \"es-catalog\",\n    \"delayed_unassigned_shards\": 0,\n    \"initializing_shards\": 0,\n    \"number_of_data_nodes\": 3,\n    \"number_of_in_flight_fetch\": 0,\n    \"number_of_nodes\": 3,\n    \"number_of_pending_tasks\": 0,\n    \"relocating_shards\": 0,\n    \"status\": \"green\",\n    \"task_max_waiting_in_queue_millis\": 0,\n    \"timed_out\": false,\n    \"unassigned_shards\": 0\n}\n<\/pre>\n<p>Among those details we are looking for <code>status<\/code> indicator which should be set to <code>green<\/code>, meaning that that all shards are allocated and cluster is in a good operational shape.<\/p>\n<h2><a name=\"indices\"><\/a>3. All About Indices<\/h2>\n<p>Our <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> cluster is all green and ready to rock. The next logical step would be to create a <code>catalog<\/code> index, with the mapping types and settings we have outlined before. But before doing that, let us check if there are any <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices-stats.html\">indices already created<\/a> this time using <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices.html\">Indices APIs<\/a>.<\/p>\n<pre class=\"brush:bash\">$ http http:\/\/localhost:9200\/_stats\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"_all\": {\n        \"primaries\": {},\n        \"total\": {}\n    },\n    \"_shards\": {\n        \"failed\": 0,\n        \"successful\": 0,\n        \"total\": 0\n    },\n    \"indices\": {}\n}\n<\/pre>\n<p>As expected, our cluster has nothing in it yet and we are good to go with creating the index for our book catalog. As we know, <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> speaks <a href=\"http:\/\/www.json.org\/\">JSON<\/a> but manipulating ald be said about usag more or less complex <a href=\"http:\/\/www.json.org\/\">JSON<\/a> document from the command line is somewhat cumbersome. Let us better store the <code>catalog<\/code> settings and mappings in the <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/02\/catalog-index.json_.txt\">catalog-index.json<\/a> document.<\/p>\n<pre class=\"brush:bash\">{ \n  \"settings\": {\n    \"index\" : {\n      \"number_of_shards\" : 5, \n      \"number_of_replicas\" : 2 \n    }\n  },\n  \"mappings\": {\n    \"books\": {\n      \"_source\" : {\n        \"enabled\": true\n      },\n      \"properties\": {\n        \"title\": { \"type\": \"text\" },\n        \"categories\" : {\n          \"type\": \"nested\",\n          \"properties\" : {\n            \"name\": { \"type\": \"text\" }\n          }\n        },\n        \"publisher\": { \"type\": \"keyword\" },\n        \"description\": { \"type\": \"text\" },\n        \"published_date\": { \"type\": \"date\" },\n        \"isbn\": { \"type\": \"keyword\" },\n        \"rating\": { \"type\": \"byte\" }\n       }\n   },\n   \"authors\": {\n     \"properties\": {\n       \"first_name\": { \"type\": \"keyword\" },\n       \"last_name\": { \"type\": \"keyword\" }\n     },\n     \"_parent\": {\n        \"type\": \"books\"\n      }\n    }\n  }\n}<\/pre>\n<p>And use this document as an input to <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices-create-index.html\">create an index API<\/a>.<\/p>\n<pre class=\"brush:bash\">$ http PUT http:\/\/localhost:9200\/catalog &lt; catalog-index.json\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"acknowledged\": true,\n    \"shards_acknowledged\": true\n}\n<\/pre>\n<p>A few words should be said about the usage of <code>acknowledged<\/code> response property across most of the <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> APIs, especially the ones which apply mutations. In general, this value simply indicates whether the operation completed before the timeout (<code>\u201ctrue\u201d<\/code>) or may take an effect sometime soon (<code>\u201cfalse\u201d<\/code>). We are going to see more examples of its usage in a different context later on.<\/p>\n<p>That is it and we have brought our <code>catalog<\/code> index live. To ensure the truthiness of this fact, we could ask <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> to return <code>catalog<\/code> <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices-get-settings.html\">index settings<\/a>.<\/p>\n<pre class=\"brush:bash\">$ http http:\/\/localhost:9200\/catalog\/_settings\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"catalog\": {\n        \"settings\": {\n            \"index\": {\n                \"creation_date\": \"1487428863824\",\n                \"number_of_replicas\": \"2\",\n                \"number_of_shards\": \"5\",\n                \"provided_name\": \"catalog\",\n                \"uuid\": \"-b63dCesROC5UawbHz8IYw\",\n                \"version\": {\n                    \"created\": \"5020099\"\n                }\n            }\n        }\n    }\n}\n<\/pre>\n<p>Awesome, exactly what we have ordered. You might wonder how <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> would react if we would have tried to <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices-update-settings.html\">update the index settings<\/a> by increasing the number of shards (as we know, not all index settings could be updated once index has been created).<\/p>\n<pre class=\"brush:bash\">$ echo '{\"index\":{\"number_of_shards\":6}}' | http PUT http:\/\/localhost:9200\/catalog\/_settings\n\nHTTP\/1.1 400 Bad Request\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"error\": {\n        \"reason\": \"can't change the number of shards for an index\",\n        \"root_cause\": [\n            ...\n        ],\n        \"type\": \"illegal_argument_exception\"\n    },\n    \"status\": 400\n}\n<\/pre>\n<p>The error response comes as no surprise (please notice that the response details have been reduced for illustrative purposes only). Along with settings, it is very easy to <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices-get-mapping.html\">get the mapping types<\/a> for a particular index, for example:<\/p>\n<pre class=\"brush:bash\">$ http http:\/\/192.168.99.100:9200\/catalog\/_mapping\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"catalog\": {\n        \"mappings\": {\n            \"authors\": {\n                ...\n            },\n            \"books\": {\n                ...\n            }\n        }\n    }\n}\n<\/pre>\n<p>By and large, the index mappings for existing fields cannot be updated; however there <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices-put-mapping.html\">are some exceptions of the rule<\/a>. One of the greatest features of the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices-analyze.html\">indices APIs<\/a> is the ability to <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices-analyze.html\">perform the analysis process<\/a> against a particular index mapping type and field without actually sending any documents.<\/p>\n<pre class=\"brush:bash\">$ http http:\/\/localhost:9200\/catalog\/_analyze field=books.title text=\"Elasticsearch: The Definitive Guide. A Distributed Real-Time Search and Analytics Engine\"\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"tokens\": [\n        {\n            \"end_offset\": 13,\n            \"position\": 0,\n            \"start_offset\": 0,\n            \"token\": \"elasticsearch\",\n            \"type\": \"\"\n        },\n        {\n            \"end_offset\": 18,\n            \"position\": 1,\n            \"start_offset\": 15,\n            \"token\": \"the\",\n            \"type\": \"\"\n        },\n        \n        ...\n\n        {\n            \"end_offset\": 88,\n            \"position\": 11,\n            \"start_offset\": 82,\n            \"token\": \"engine\",\n            \"type\": \"\"\n        }\n    ]\n}\n<\/pre>\n<p>It is exceptionally useful in case you would like to validate your mapping types\u2019 parameters before throwing a bunch of data into <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> for indexing.<\/p>\n<p>And last but not least, there is one important detail about index states. Any particular index could be in <code>opened<\/code> (fully operational) or <code>closed<\/code> (blocked for read\/write operations, archived would be a good analogy) states. As for everything else, <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> provided an <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices-open-close.html\">APIs for that<\/a>.<\/p>\n<pre class=\"brush:bash\">$ http POST http:\/\/localhost:9200\/catalog\/_open\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"acknowledged\": true\n}\n<\/pre>\n<h2><a name=\"documents\"><\/a>4. Documents, More Documents, \u2026<\/h2>\n<p>The empty index without documents is not very useful so let us switch gears from <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/indices.html\">indices APIs<\/a> to another great one, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs.html\">document APIs<\/a>. We are going to start exploring it using the simplest <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-index_.html\">single document<\/a> operations, relying on the following <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/02\/book.json_.txt\">book.json<\/a> document:<\/p>\n<pre class=\"brush:bash\">{\n  \"title\": \"Elasticsearch: The Definitive Guide. A Distributed Real-Time Search and Analytics Engine\",\n  \"categories\": [\n      { \"name\": \"analytics\" },\n      { \"name\": \"search\" },\n      { \"name\": \"database store\" }\n  ],\n  \"publisher\": \"O'Reilly\",\n  \"description\": \"Whether you need full-text search or real-time analytics of structured data\u2014or both\u2014the Elasticsearch distributed search engine is an ideal way to put your data to work. This practical guide not only shows you how to search, analyze, and explore data with Elasticsearch, but also helps you deal with the complexities of human language, geolocation, and relationships.\", \n  \"published_date\": \"2015-02-07\",\n  \"isbn\": \"978-1449358549\",\n  \"rating\": 4\n}\n<\/pre>\n<p>Before sending this <a href=\"http:\/\/www.json.org\/\">JSON<\/a> to <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a>, it would be great to talk a little bit about documents identification. Each document in <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> has a unique identifier, stored in a special <code>_id<\/code> field. You may provide one while uploading the document to <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> (like we do in the example below using <code>isbn<\/code> as it is a great example of natural identifier), or it will be generated and assigned by <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a>.<\/p>\n<pre class=\"brush:bash\">$ http PUT http:\/\/localhost:9200\/catalog\/books\/978-1449358549 &lt; book.json\n\nHTTP\/1.1 201 Created\nLocation: \/catalog\/books\/978-1449358549\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"_id\": \"978-1449358549\",\n    \"_index\": \"catalog\",\n    \"_shards\": {\n        \"failed\": 0,\n        \"successful\": 3,\n        \"total\": 3\n    },\n    \"_type\": \"books\",\n    \"_version\": 1,\n    \"created\": true,\n    \"result\": \"created\"\n}\n<\/pre>\n<p>Our first document just made its way into a <code>catalog<\/code> index, under <code>books<\/code> type. But we also have <code>authors<\/code> type, which is in a parent \/ child relationship with <code>books<\/code>. Let us complement the book with its authors from <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/02\/authors.json_.txt\">authors.json<\/a> document.<\/p>\n<pre class=\"brush:bash\">[\n  {\n    \"first_name\": \"Clinton\",\n    \"last_name\": \"Gormley\",\n    \"_parent\": \"978-1449358549\"\n  },\n  {\n    \"first_name\": \"Zachary\",\n    \"last_name\": \"Tong\",\n    \"_parent\": \"978-1449358549\"\n  }\n]\n<\/pre>\n<p>The book has more than one author so we still can use the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-index_.html\">single document API<\/a> by indexing each author document one by one. However, let us not do that but switch over to <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-bulk.html\">bulk document API<\/a> instead and transform our <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/02\/authors.json_.txt\">authors.json<\/a> document a bit to be compatible with <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-bulk.html\">bulk document API<\/a> format.<\/p>\n<pre class=\"brush:bash\">{ \"index\" : { \"_index\" : \"catalog\", \"_type\" : \"authors\", \"_id\": \"1\", \"_parent\": \"978-1449358549\" } }\n{ \"first_name\": \"Clinton\", \"last_name\": \"Gormley\" }\n{ \"index\" : { \"_index\" : \"catalog\", \"_type\" : \"authors\", \"_id\": \"2\", \"_parent\": \"978-1449358549\" } }\n{ \"first_name\": \"Zachary\", \"last_name\": \"Tong\" }\n<\/pre>\n<p>Done deal, let us save this document as <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/02\/authors-bulk.json_.txt\">authors-bulk.json<\/a> and feed it directly into <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-bulk.html\">bulk document API<\/a> endpoint.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:bash\">$ http POST http:\/\/localhost:9200\/_bulk &lt; authors-bulk.json\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"errors\": false,\n    \"items\": [\n        {\n            \"index\": {\n                \"_id\": \"1\",\n                \"_index\": \"catalog\",\n                \"_shards\": {\n                    \"failed\": 0,\n                    \"successful\": 3,\n                    \"total\": 3\n                },\n                \"_type\": \"authors\",\n                \"_version\": 5,\n                \"created\": false,\n                \"result\": \"updated\",\n                \"status\": 200\n            }\n        },\n        {\n            \"index\": {\n                \"_id\": \"2\",\n                \"_index\": \"catalog\",\n                \"_shards\": {\n                    \"failed\": 0,\n                    \"successful\": 3,\n                    \"total\": 3\n                },\n                \"_type\": \"authors\",\n                \"_version\": 2,\n                \"created\": true,\n                \"result\": \"created\",\n                \"status\": 201\n            }\n        }\n    ],\n    \"took\": 105\n}\n<\/pre>\n<p>And we have book and author documents as the first citizens of the <code>catalog<\/code> index! It is time to <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-get.html\">fetch those documents<\/a> back.<\/p>\n<pre class=\"brush:bash\">$ http http:\/\/localhost:9200\/catalog\/books\/978-1449358549\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"_id\": \"978-1449358549\",\n    \"_index\": \"catalog\",\n    \"_source\": {\n        \"categories\": [\n            { \"name\": \"analytics\" },\n            { \"name\": \"search\"},\n            { \"name\": \"database store\" }\n        ],\n        \"description\": \"...\",\n        \"isbn\": \"978-1449358549\",\n        \"published_date\": \"2015-02-07\",\n        \"publisher\": \"O'Reilly\",\n        \"rating\": 4,\n        \"title\": \"Elasticsearch: The Definitive Guide. A Distributed Real-Time Search and Analytics Engine\"\n    },\n    \"_type\": \"books\",\n    \"_version\": 1,\n    \"found\": true\n}\n<\/pre>\n<p>Easy! However to fetch the documents from <code>authors<\/code> collection, which are children of their respective documents from <code>books<\/code> collection, we have to supply the parent identifier along with the document own one, for example:<\/p>\n<pre class=\"brush:bash\">$ http http:\/\/localhost:9200\/catalog\/authors\/1?parent=978-1449358549\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"_id\": \"1\",\n    \"_index\": \"catalog\",\n    \"_parent\": \"978-1449358549\",\n    \"_routing\": \"978-1449358549\",\n    \"_source\": {\n        \"first_name\": \"Clinton\",\n        \"last_name\": \"Gormley\"\n    },\n    \"_type\": \"authors\",\n    \"_version\": 1,\n    \"found\": true\n}\n<\/pre>\n<p>This is one of the specifics working with parent \/ child relations in <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a>. As it has been already mentioned, you may model such relationships in a simpler way but our goal is to learn how to deal with it if you choose to go this route in your applications.<\/p>\n<p>The <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-delete.html\">delete<\/a> and <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-update.html\">update<\/a> APIs are pretty straightforward so we just leaf them through, please notice that the same rules regarding identifying the child documents apply. You may be surprised, but deleting a parent document does not automatically delete its children, so keep that in mind. We are going to see how to workaround that a bit later.<\/p>\n<p>To finish up, let us take a look at the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-termvectors.html\">term vectors API<\/a> which returns all the details and statistics about terms in the fields of the document, for example (only the small part of the response has been pasted):<\/p>\n<pre class=\"brush:bash\">$ http http:\/\/localhost:9200\/catalog\/books\/978-1449358549\/_termvectors?fields=description\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"_id\": \"978-1449358549\",\n    \"_index\": \"catalog\",\n    \"_type\": \"books\",\n    \"_version\": 1,\n    \"found\": true,\n    \"term_vectors\": {\n        \"description\": {\n            \"field_statistics\": {\n                \"doc_count\": 1,\n                \"sum_doc_freq\": 46,\n                \"sum_ttf\": 60\n            },\n            \"terms\": {\n                \"analyze\": {\n                    \"term_freq\": 1,\n                    \"tokens\": [ ... ]\n                },\n                \"and\": {\n                    \"term_freq\": 2,\n                    \"tokens\": [ ... ]\n\n                },\n                \"complexities\": {\n                    \"term_freq\": 1,\n                    \"tokens\": [ ... ]\n\n                },\n                \"data\": {\n                    \"term_freq\": 3,\n                    \"tokens\": [ ... ]\n\n                },\n                ...\n            }\n        }\n    },\n    \"took\": 5\n}\n<\/pre>\n<p>You may not find yourself using the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-termvectors.html\">term vectors API<\/a> often however it is a terrific tool to troubleshoot why certain documents may not pop up in the search results.<\/p>\n<h2><a name=\"mapping\"><\/a>5. What if My Mapping Types Are Suboptimal<\/h2>\n<p>Very often over time you may discover that your mapping types may not be optimal and could be made better. However, <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> supports only limited modifications over existing mapping types. Luckily, <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> is providing a dedicated <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-reindex.html\">reindexing API<\/a>, for example:<\/p>\n<pre class=\"brush:bash\">$ echo '{\"source\": {\"index\": \"catalog\"}, \"dest\": {\"index\": \"catalog-v2\"}}' | http POST http:\/\/localhost:9200\/_reindex\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"batches\": 0,\n    \"created\": 200,\n    \"deleted\": 0,\n    \"failures\": [],\n    \"noops\": 0,\n    \"requests_per_second\": -1.0,\n    \"retries\": {\n        \"bulk\": 0,\n        \"search\": 0\n    },\n    \"throttled_millis\": 0,\n    \"throttled_until_millis\": 0,\n    \"timed_out\": false,\n    \"took\": 265,\n    \"total\": 200,\n    \"updated\": 0,\n    \"version_conflicts\": 0\n}\n<\/pre>\n<p>The trick here is to create a new index with updated mapping types, <code>catalog-v2<\/code>, and than just ask <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> to fetch all documents from old index (<code>catalog<\/code>) and put them into the new one (<code>catalog-v2<\/code>), and finally swap the indices. Please notice, it also works not only for local but <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-reindex.html#reindex-from-remote\">remote indices as well<\/a>.<\/p>\n<p>Although simple, this API is still considered an experimental and may not be suitable in all cases, for example if your index is really massive or your <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> is experiencing a high load and should prioritize the application requests.<br \/>\n[ulp id=&#8217;lFK4fMZhpULqeQUl&#8217;]<br \/>\n&nbsp;<\/p>\n<h2><a name=\"search\"><\/a>6. The Search Time<\/h2>\n<p>We have learned how to create indexes, mapping types and index the documents, all important but not really exciting topics. But search is definitely the heart and soul of <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a>, so let us get to know it right away.<\/p>\n<p>In order to demonstrate different search features we would need a couple of more documents, please upload them to your <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> cluster from <a href=\"http:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/02\/books-and-authors-bulk.json_.txt\">books-and-authors-bulk.json<\/a> using our friend <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-bulk.html\">bulk document API<\/a>.<\/p>\n<pre class=\"brush:bash\">$ http POST http:\/\/localhost:9200\/_bulk &lt; books-and-authors-bulk.json\n<\/pre>\n<p>Having a few documents in our collections we could start off to issue search queries against them using the most accessible form of <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-search.html\">search API<\/a> which accepts search criteria <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-uri-request.html\">in URI<\/a> by means of query string. For example, let us search for a term <code>engine<\/code> (keeping in mind <code>search engine<\/code> phrase).<\/p>\n<pre class=\"brush:bash\">$ http POST http:\/\/localhost:9200\/catalog\/books\/_search?q=engine\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"_shards\": {\n        \"failed\": 0,\n        \"successful\": 5,\n        \"total\": 5\n    },\n    \"hits\": {\n        \"hits\": [\n            {\n                \"_id\": \"978-1449358549\",\n                \"_index\": \"catalog\",\n                \"_score\": 0.7503276,\n                \"_source\": {\n                    \"categories\": [\n                        { \"name\": \"analytics },\n                        { \"name\": \"search\" },\n                        { \"name\": \"database store\" }\n                    ],\n                    \"description\": \" Whether you need full-text search or real-time ...\",\n                    \"isbn\": \"978-1449358549\",\n                    \"published_date\": \"2015-02-07\",\n                    \"publisher\": \"O'Reilly\",\n                    \"rating\": 4,\n                    \"title\": \" Elasticsearch: The Definitive Guide. ...\"\n                },\n                \"_type\": \"books\"\n            }\n        ],\n        \"max_score\": 0.7503276,\n        \"total\": 1\n    },\n    \"timed_out\": false,\n    \"took\": 22\n}\n<\/pre>\n<p>Good starting point indeed, this API is quite useful for doing quick and shallow searches, but its capabilities are very limited. The <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-request-body.html\">search using request body API<\/a> is a very different beast and reveals the full power of <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a>. It is built on top of <a href=\"http:\/\/www.json.org\/\">JSON<\/a>-based <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl.html\">Query DSL<\/a>, the concise and intuitive language to construct arbitrarily complex search queries.<\/p>\n<p>There are quite a few query types which <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl.html\">Query DSL<\/a> allows to describe, each have own syntax and parameters. However, there is a set of common parameters, like <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-request-sort.html\">sort<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-request-from-size.html\">from<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-request-from-size.html\">size<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-request-stored-fields.html\">stored_fields<\/a> (the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-request-body.html\">list is really long<\/a> actually) which are agnostic to query type and could be applied for any of those.<\/p>\n<p>For the next couple of sections we are going to switch over from <a href=\"https:\/\/httpie.org\/\">http<\/a> to <a href=\"https:\/\/curl.haxx.se\/\">curl<\/a> as the latter is a bit more convenient when dealing with <a href=\"http:\/\/www.json.org\/\">JSON<\/a> payloads.<\/p>\n<p>The first query type we are going to try out using <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl.html\">Query DSL<\/a> is the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-match-all-query.html\">match all query<\/a>. In some extent, it is not really a query because it just matches all documents. As such, it may return a lot of results and as a general rule, please always annotate your queries with reasonable <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-request-from-size.html\">size<\/a> limit, here is an example:<\/p>\n<pre class=\"brush:bash\">$ curl \u2013i http:\/\/localhost:9200\/catalog\/books\/_search?pretty -d '                                                                                                                                  \n{\n    \"size\": 10,\n    \"query\": {\n        \"match_all\" : {\n        }\n    }\n}'\n\nHTTP\/1.1 200 OK\ncontent-type: application\/json; charset=UTF-8\ncontent-length: 3112\n{\n  \"took\" : 13,\n  \"timed_out\" : false,\n  \"_shards\" : {\n    \"total\" : 5,\n    \"successful\" : 5,\n    \"failed\" : 0\n  },\n  \"hits\" : {\n    \"total\" : 3,\n    \"max_score\" : 1.0,\n    \"hits\" : [\n      {\n        \"_index\" : \"catalog\",\n        \"_type\" : \"books\",\n        \"_id\" : \"978-1449358549\",\n        \"_score\" : 1.0,\n        \"_source\" : {\n          \"title\" : \"Elasticsearch: The Definitive Guide ...\",\n          \"categories\" : [\n            { \"name\" : \"analytics\" },\n            { \"name\" : \"search\" },\n            { \"name\" : \"database store\" }\n          ],\n          \"publisher\" : \"O'Reilly\",\n          \"description\" : \"Whether you need full-text ...\",\n          \"published_date\" : \"2015-02-07\",\n          \"isbn\" : \"978-1449358549\",\n          \"rating\" : 4\n        }\n      },\n      ...\n    ]\n  }\n}\n<\/pre>\n<p>The next one is a real query type and is referred as a class of <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/full-text-queries.html\">full text queries<\/a> which do a search against full text document fields (probably the most widely used ones). In the basic form it does a match against a single document field, like for example book\u2019s <code>description<\/code>.<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/_search?pretty -d '\n{\n    \"query\": {\n        \"match\" : {\n            \"description\" : \"engine\"\n        }\n    }\n}'\n\nHTTP\/1.1 200 OK\ncontent-type: application\/json; charset=UTF-8\ncontent-length: 1271\n{\n  \"took\" : 17,\n  \"timed_out\" : false,\n  \"_shards\" : {\n    \"total\" : 5,\n    \"successful\" : 5,\n    \"failed\" : 0\n  },\n  \"hits\" : {\n    \"total\" : 1,\n    \"max_score\" : 0.28004453,\n    \"hits\" : [\n      {\n        \"_index\" : \"catalog\",\n        \"_type\" : \"books\",\n        \"_id\" : \"978-1449358549\",\n        \"_score\" : 0.28004453,\n        \"_source\" : {\n          \"title\" : \"Elasticsearch: The Definitive Guide. ...\",\n          \"categories\" : [\n            { \"name\" : \"analytics\" },\n            { \"name\" : \"search\" },\n            { \"name\" : \"database store\" }\n          ],\n          \"publisher\" : \"O'Reilly\",\n          \"description\" : \"Whether you need full-text ...\",\n          \"published_date\" : \"2015-02-07\",\n          \"isbn\" : \"978-1449358549\",\n          \"rating\" : 4\n        }\n      }\n    ]\n  }\n}\n<\/pre>\n<p>But the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/full-text-queries.html\">full text queries<\/a> are very powerful and have quite a few other variations, including <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-match-query-phrase.html\">match_phrase<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-match-query-phrase-prefix.html\">match_phrase_prefix<\/a>, \u00a0<a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-multi-match-query.html\">multi_match<\/a>, \u00a0<a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-common-terms-query.html\">common_terms<\/a>, \u00a0<a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-query-string-query.html\">query_string<\/a> and <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-simple-query-string-query.html\">simple_query_string<\/a>.<\/p>\n<p>Moving on, we are entering the world of <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/term-level-queries.html\">term level queries<\/a> which operate on the exact terms and usually used for field types like numbers, dates, and keywords. The <code>publisher<\/code> book field is a good candidate to try it out.<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/_search?pretty -d '\n{\n   \"size\": 10,\n   \"_source\": [ \"title\" ],\n   \"query\": {\n        \"term\" : {\n            \"publisher\" : \"Manning\"\n        }\n    }\n}'  \n\nHTTP\/1.1 200 OK\ncontent-type: application\/json; charset=UTF-8\ncontent-length: 675\n\n{\n  \"took\" : 21,\n  \"timed_out\" : false,\n  \"_shards\" : {\n    \"total\" : 5,\n    \"successful\" : 5,\n    \"failed\" : 0\n  },\n  \"hits\" : {\n    \"total\" : 2,\n    \"max_score\" : 0.18232156,\n    \"hits\" : [\n      {\n        \"_index\" : \"catalog\",\n        \"_type\" : \"books\",\n        \"_id\" : \"978-1617291623\",\n        \"_score\" : 0.18232156,\n        \"_source\" : {\n          \"title\" : \"Elasticsearch in Action\"\n        }\n      },\n      {\n        \"_index\" : \"catalog\",\n        \"_type\" : \"books\",\n        \"_id\" : \"978-1617292774\",\n        \"_score\" : 0.18232156,\n        \"_source\" : {\n          \"title\" : \"Relevant Search: With applications ...\"\n        }\n      }\n    ]\n  }\n}\n<\/pre>\n<p>Please notice how we have limited the properties of document\u2019s <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-request-source-filtering.html\">_source<\/a> to return <code>title<\/code> field only. The other variations of <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/term-level-queries.html\">term level queries<\/a> include <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-terms-query.html\">terms<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-range-query.html\">range<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-exists-query.html\">exists<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-prefix-query.html\">prefix<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-wildcard-query.html\">wildcard<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-regexp-query.html\">regexp<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-fuzzy-query.html\">fuzzy<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-type-query.html\">type<\/a> and <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-ids-query.html\">ids<\/a>.<\/p>\n<p><a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/joining-queries.html\">Joining queries<\/a> are exceptionally interesting ones in the context of our book <code>catalog<\/code> index. Those queries allow to perform the search against nested objects or documents with parent\/child relationship. For example, let us find out all the books in the <code>analytics<\/code> category.<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/_search?pretty -d '\n{\n   \"size\": 10,\n   \"_source\": [ \"title\", \"categories\" ],\n   \"query\": {\n        \"nested\": {\n            \"path\": \"categories\",\n            \"query\" : {\n                \"match\": {\n                    \"categories.name\" : \"analytics\"\n                }\n            }\n       }\n    }\n}'\n\nHTTP\/1.1 200 OK\ncontent-type: application\/json; charset=UTF-8\ncontent-length: 1177\n\n{\n  \"took\" : 45,\n  \"timed_out\" : false,\n  \"_shards\" : {\n    \"total\" : 5,\n    \"successful\" : 5,\n    \"failed\" : 0\n  },\n  \"hits\" : {\n    \"total\" : 2,\n    \"max_score\" : 1.3112576,\n    \"hits\" : [\n      {\n        \"_index\" : \"catalog\",\n        \"_type\" : \"books\",\n        \"_id\" : \"978-1617291623\",\n        \"_score\" : 1.3112576,\n        \"_source\" : {\n          \"categories\" : [\n            { \"name\" : \"analytics\" },\n            { \"name\" : \"search\" },\n            { \"name\" : \"database store\" }\n          ],\n          \"title\" : \"Elasticsearch in Action\"\n        }\n      },\n      {\n        \"_index\" : \"catalog\",\n        \"_type\" : \"books\",\n        \"_id\" : \"978-1449358549\",\n        \"_score\" : 1.0925692,\n        \"_source\" : {\n          \"categories\" : [\n            { \"name\" : \"analytics\" },\n            { \"name\" : \"search\" },\n            { \"name\" : \"database store\" }\n          ],\n          \"title\" : \"Elasticsearch: The Definitive Guide ...\"\n        }\n      }\n    ]\n  }\n} \n<\/pre>\n<p>Similarly, we could have searched for all the books authored by <a href=\"http:\/\/www.oreilly.com\/pub\/au\/6109\">Clinton Gormley<\/a>, leveraging parent\/child relationships between <code>books<\/code> and <code>authors<\/code> collections.<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/_search?pretty -d '\n{\n   \"size\": 10,\n   \"_source\": [ \"title\" ],\n   \"query\": {\n       \"has_child\" : {\n            \"type\" : \"authors\",\n            \"inner_hits\" : {\n                \"size\": 5\n            },\n            \"query\" : {\n                \"term\" : {\n                    \"last_name\" : \"Gormley\"\n                }\n            }\n        }\n    }\n}'\n\nHTTP\/1.1 200 OK\ncontent-type: application\/json; charset=UTF-8\ncontent-length: 1084\n\n{\n  \"took\" : 38,\n  \"timed_out\" : false,\n  \"_shards\" : {\n    \"total\" : 5,\n    \"successful\" : 5,\n    \"failed\" : 0\n  },\n  \"hits\" : {\n    \"total\" : 1,\n    \"max_score\" : 1.0,\n    \"hits\" : [\n      {\n        \"_index\" : \"catalog\",\n        \"_type\" : \"books\",\n        \"_id\" : \"978-1449358549\",\n        \"_score\" : 1.0,\n        \"_source\" : {\n          \"title\" : \"Elasticsearch: The Definitive Guide ...\"\n        },\n        \"inner_hits\" : {\n          \"authors\" : {\n            \"hits\" : {\n              \"total\" : 1,\n              \"max_score\" : 0.6931472,\n              \"hits\" : [\n                {\n                  \"_type\" : \"authors\",\n                  \"_id\" : \"1\",\n                  \"_score\" : 0.6931472,\n                  \"_routing\" : \"978-1449358549\",\n                  \"_parent\" : \"978-1449358549\",\n                  \"_source\" : {\n                    \"first_name\" : \"Clinton\",\n                    \"last_name\" : \"Gormley\"\n                  }\n                }\n              ]\n            }\n          }\n        }\n      }\n    ]\n  }\n}\n<\/pre>\n<p>Please pay attention to the presence of <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-request-inner-hits.html\">inner_hits<\/a> query parameter which let the search results to include the inner documents that matched the joining criteria.<\/p>\n<p>The other query types like <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/geo-queries.html\">Geo queries<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/specialized-queries.html\">specialized queries<\/a> and <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/span-queries.html\">span queries<\/a> work in a very similar way so we would just skip over them and finish up by looking into <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/compound-queries.html\">composite queries<\/a>. The examples we have seen so far included the queries with only one search criteria but <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl.html\">Query DSL<\/a> has a way to construct the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/compound-queries.html\">compound queries<\/a> as well. Let us take a look at the example of using <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl-bool-query.html\">bool <\/a>query which is the composition of some of the query types we have seen already.<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/_search?pretty -d '\n{\n   \"size\": 10,\n   \"_source\": [ \"title\", \"publisher\" ],\n   \"query\": {\n       \"bool\" : {\n          \"must\" : [\n              {\n                  \"range\" : {\n                      \"rating\" : { \"gte\" : 4 }\n                  }\n              },\n              {\n                  \"has_child\" : {\n                      \"type\" : \"authors\",\n                      \"query\" : {\n                          \"term\" : {\n                              \"last_name\" : \"Gormley\"\n                          }\n                      }\n                  }\n              },\n              {\n                  \"nested\": {\n                      \"path\": \"categories\",\n                      \"query\" : {\n                          \"match\": {\n                              \"categories.name\" : \"search\"\n                          }\n                      }\n                  }\n              }\n          ]\n       }\n    }\n}'\n\nHTTP\/1.1 200 OK\ncontent-type: application\/json; charset=UTF-8\ncontent-length: 531\n\n{\n  \"took\" : 79,\n  \"timed_out\" : false,\n  \"_shards\" : {\n    \"total\" : 5,\n    \"successful\" : 5,\n    \"failed\" : 0\n  },\n  \"hits\" : {\n    \"total\" : 1,\n    \"max_score\" : 3.0925694,\n    \"hits\" : [\n      {\n        \"_index\" : \"catalog\",\n        \"_type\" : \"books\",\n        \"_id\" : \"978-1449358549\",\n        \"_score\" : 3.0925694,\n        \"_source\" : {\n          \"publisher\" : \"O'Reilly\",\n          \"title\" : \"Elasticsearch: The Definitive Guide.  ...\"\n        }\n      }\n    ]\n  }\n}\n<\/pre>\n<p>It would be fair to say that the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-search.html\">search API<\/a> of <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> powered by <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl.html\">Query DSL<\/a> is exceptionally flexible, easy to use and expressive. More to that, it is worth to mention that additionally to queries the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-search.html\">search API<\/a> also supports the concept of <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-filter-context.html\">filters<\/a> which offer yet another option to exclude the document from the search results.<\/p>\n<h2><a name=\"mutations\"><\/a>7. Mutations by Query<\/h2>\n<p>Surprisingly (or not), queries could be used by <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> to perform mutations like <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-update-by-query.html\">updates<\/a> or <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-delete-by-query.html\">deletes<\/a> over the documents in the index. For example, the following snippet will remove all the books which have low rating in our catalog, published by <code>Manning<\/code>.<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/_delete_by_query?pretty -d '\n{\n   \"query\": {\n      \"bool\": {\n          \"must\": [\n              { \"range\" : { \"rating\" : { \"lt\" : 3 } } }\n          ],\n          \"filter\": [\n             { \"term\" :  { \"publisher\" : \"Manning\" } }\n          ]\n      }\n   }\n}'\n\nHTTP\/1.1 200 OK\ncontent-type: application\/json; charset=UTF-8\ncontent-length: 296\n\n{\n  \"took\" : 12,\n  \"timed_out\" : false,\n  \"total\" : 0,\n  \"deleted\" : 0,\n  \"batches\" : 0,\n  \"version_conflicts\" : 0,\n  \"noops\" : 0,\n  \"retries\" : {\n    \"bulk\" : 0,\n    \"search\" : 0\n  },\n  \"throttled_millis\" : 0,\n  \"requests_per_second\" : -1.0,\n  \"throttled_until_millis\" : 0,\n  \"failures\" : [ ]\n}\n<\/pre>\n<p>It uses the same <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/query-dsl.html\">Query DSL<\/a> and, for the purpose of illustration of how filtering could be used, includes <code>filter<\/code> as part of the query. But instead of returning the matched documents, the update or delete modifications are going to be applied.<\/p>\n<p>The <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/docs-delete-by-query.html\">delete by query API<\/a> could be used to overcome the limitations of regular <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/5.2\/docs-delete.html\">delete API<\/a> and remove the child documents in case their parent is deleted.<\/p>\n<h2><a name=\"queries\"><\/a>8. Know Your Queries Better<\/h2>\n<p>Sometimes you may find out that your search queries are returning the documents in order you don\u2019t expect, ranking some documents higher than others. To help you out, <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> provides two very helpful APIs. One of these is <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-explain.html\">explain API<\/a>, which computes a score explanation for a query (and a specific document if needed).<\/p>\n<p>The explanation could be received by specifying the <code>explain<\/code> parameter as part of query:<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/_search?pretty -d '\n{\n   \"size\": 10,\n   \"explain\": true,\n   \"query\": {\n        \"term\" : {\n            \"publisher\" : \"Manning\"\n        }\n    }\n}\n<\/pre>\n<p>Or using dedicated <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-explain.html\">explain API endpoint<\/a> and specific document, for example:<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/978-1617292774\/_explain?pretty -d '\n{\n   \"query\": {\n        \"term\" : {\n            \"publisher\" : \"Manning\"\n        }\n    }\n}'\n<\/pre>\n<p>The responses have not been included intentionally as the tons of useful details are being returned. Another very useful feature of <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> is <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-validate.html\">validation API<\/a> which allows to perform a validation of the query without actually executing it, for example:<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/_validate\/query?pretty -d ' {\n   \"query\": {\n        \"term\" : {\n            \"publisher\" : \"Manning\"\n        }\n    }                            \n}'\n\nHTTP\/1.1 200 OK\ncontent-type: application\/json; charset=UTF-8\ncontent-length: 98\n\n{\n  \"valid\" : true,\n  \"_shards\" : {\n    \"total\" : 1,\n    \"successful\" : 1,\n    \"failed\" : 0\n  }\n}\n<\/pre>\n<p>Both APIs are very useful to troubleshoot the relevance or analyze potentially impactful search query without executing it on a live <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> cluster.<\/p>\n<h2><a name=\"insights\"><\/a>9. From Search to Insights<\/h2>\n<p>Often you may find yourself in the situation when the search is just not enough, you need some kind of aggregations on top of the matches. The great example would be faceting (or as <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> calls it, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-aggregations-bucket-terms-aggregation.html\">terms aggregations<\/a>), where the search results are grouped into buckets.<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/_search?pretty -d '\n{\n   \"query\": {\n        \"match\" : {\n            \"description\" : \"elasticsearch\"\n        }\n    },\n    \"aggs\" : {\n        \"publisher\" : {\n            \"terms\" : { \"field\" : \"publisher\" }\n        }\n    }\n}'\n\nHTTP\/1.1 200 OK\ncontent-type: application\/json; charset=UTF-8\ncontent-length: 3447\n\n{\n  \"took\" : 176,\n  \"timed_out\" : false,\n  \"_shards\" : {\n    \"total\" : 5,\n    \"successful\" : 5,\n    \"failed\" : 0\n  },\n  \"hits\" : {\n    \"total\" : 3,\n    \"max_score\" : 0.38828257,\n    \"hits\" : [\n      {\n          ...\n      }\n    ]\n  },\n  \"aggregations\" : {\n    \"publisher\" : {\n      \"doc_count_error_upper_bound\" : 0,\n      \"sum_other_doc_count\" : 0,\n      \"buckets\" : [\n        {\n          \"key\" : \"Manning\",\n          \"doc_count\" : 2\n        },\n        {\n          \"key\" : \"O'Reilly\",\n          \"doc_count\" : 1\n        }\n      ]\n    }\n  }\n}\n<\/pre>\n<p>In this example along with the search query, we have asked <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> to count the documents by publishers. By and large, search query could be completely omitted and only aggregations could be sent in request body, for example:<\/p>\n<pre class=\"brush:bash\">$ curl -i http:\/\/localhost:9200\/catalog\/books\/_search?pretty -d '\n{\n  \"aggs\" : {\n      \"authors\": {\n        \"children\": {\n          \"type\" : \"authors\"\n        },\n        \"aggs\": {\n          \"top-authors\": {\n            \"terms\": {\n            \"script\" : {\n              \"inline\": \"doc['first_name'].value + ' ' + doc['last_name'].value\",\n              \"lang\": \"painless\"\n            },\n            \"size\": 10\n          }\n        }\n      }\n    }\n  }\n}'\n\nHTTP\/1.1 200 OK\ncontent-type: application\/json; charset=UTF-8\ncontent-length: 1031\n{\n  \"took\": 381,\n  \"timed_out\": false,\n  \"_shards\": {\n    \"total\": 5,\n    \"successful\": 5,\n    \"failed\": 0\n  },\n  \"hits\": {\n    \"total\": 5,\n    \"max_score\": 1,\n    \"hits\": [\n      ...\n    ]\n  },\n  \"aggregations\": {\n    \"authors\": {\n      \"doc_count\": 6,\n      \"top-authors\": {\n        \"doc_count_error_upper_bound\": 0,\n        \"sum_other_doc_count\": 0,\n        \"buckets\": [\n          {\n            \"key\": \"Clinton Gormley\",\n            \"doc_count\": 1\n          },\n          {\n            \"key\": \"Doug Turnbull\",\n            \"doc_count\": 1\n          },\n          {\n            \"key\": \"Matthew Lee Hinman\",\n            \"doc_count\": 1\n          },\n          {\n            \"key\": \"Radu Gheorghe\",\n            \"doc_count\": 1\n          },\n          {\n            \"key\": \"Roy Russo\",\n            \"doc_count\": 1\n          },\n          {\n            \"key\": \"Zachary Tong\",\n            \"doc_count\": 1\n          }\n        ]\n      }\n    }\n  }\n}\n<\/pre>\n<p>In this slightly more complicated example we have bucketed over top authors using <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> scripting support to compose the terms out of the author\u2019s first and last name:<\/p>\n<pre class=\"brush:bash\">\"script\" : {                           \n  \"inline\": \"doc['first_name'].value + ' ' + doc['last_name'].value\",  \n  \"lang\": \"painless\"                 \n}\n<\/pre>\n<p>The list of <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-aggregations.html\">supported aggregations<\/a> is really impressive and includes <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-aggregations-bucket.html\">bucket aggregations<\/a> (some of those we have tried out already), <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-aggregations-metrics.html\">metrics aggregations<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-aggregations-pipeline.html\">pipeline aggregations<\/a>, and <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/search-aggregations-matrix.html\">matrix aggregations<\/a>. Covering just one class of those would need its own tutorial, so please check them out to understand the purpose of each one in depth.<\/p>\n<h2><a name=\"breathing\"><\/a>10. Watch Your Cluster Breathing<\/h2>\n<p><a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> clusters are living \u201ccreatures\u201d and should be watched and monitored closely in order to proactively spot any issues and react on them quickly. The <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/cluster-health.html\">cluster health endpoint<\/a> we have seen before is the easiest way to get overall high-level status of the cluster.<\/p>\n<pre class=\"brush:bash\">$ http http:\/\/localhost:9200\/_cluster\/health\n\nHTTP\/1.1 200 OK\ncontent-encoding: gzip\ncontent-type: application\/json; charset=UTF-8\ntransfer-encoding: chunked\n\n{\n    \"active_primary_shards\": 5,\n    \"active_shards\": 5,\n    \"active_shards_percent_as_number\": 20.0,\n    \"cluster_name\": \"es-catalog\",\n    \"delayed_unassigned_shards\": 0,\n    \"initializing_shards\": 0,\n    \"number_of_data_nodes\": 1,\n    \"number_of_in_flight_fetch\": 0,\n    \"number_of_nodes\": 1,\n    \"number_of_pending_tasks\": 0,\n    \"relocating_shards\": 0,\n    \"status\": \"red\",\n    \"task_max_waiting_in_queue_millis\": 0,\n    \"timed_out\": false,\n    \"unassigned_shards\": 20\n}\n<\/pre>\n<p>If you cluster goes <code>red<\/code> (like in the example above), there is certainly a problem to fix. To help you out, <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> has <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/5.2\/cluster-stats.html\">cluster statistics API<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/5.2\/cluster-state.html\">cluster state API<\/a>, <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/5.2\/cluster-nodes-stats.html#_nodes_statistics\">cluster node level statistics API<\/a> and <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/5.2\/cluster-nodes-stats.html#node-indices-stats\">cluster node indices\u00a0 statistics API<\/a>.<\/p>\n<p>A bit aside stays another exceptionally important group of APIs, the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/5.2\/cat.html\">cat APIs<\/a>. They are different in a sense that the representation is not in <a href=\"http:\/\/www.json.org\/\">JSON<\/a> but rather text based, with compact and aligned output, suitable for terminals.<\/p>\n<h2><a name=\"conclusions\"><\/a>11. Conclusions<\/h2>\n<p>In this section of the tutorial we went through many features of the <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> by exploring them through <a href=\"https:\/\/en.wikipedia.org\/wiki\/Representational_state_transfer\">RESTful APIs<\/a>, using command line tools only. By and large, it is just a tiny part of what <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> offers through the APIs and the <a href=\"https:\/\/www.elastic.co\/guide\/en\/elasticsearch\/reference\/current\/index.html\">official documentation<\/a> is a great place to learn them all. Hopefully, at this point we are comfortable enough with <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> and know how to work with it.<\/p>\n<h2><a name=\"next\"><\/a>12. What\u2019s next<\/h2>\n<p><a href=\"https:\/\/www.javacodegeeks.com\/2017\/03\/elasticsearch-java-developers-elasticsearch-java.html\">In the next part of the tutorial<\/a> we are going to learn the several flavors of native APIs which <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> has to offer to Java\/JVM developers. These APIs are the essential building blocks of any Java\/JVM application which leverages <a href=\"https:\/\/www.elastic.co\/products\/elasticsearch\">Elasticsearch<\/a> capabilities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is part of our Academy Course titled Elasticsearch Tutorial for Java Developers. In this course, we provide a series of tutorials so that you can develop your own Elasticsearch based applications. We cover a wide range of topics, from installation and operations, to Java API Integration and reporting. With our straightforward tutorials, you &hellip;<\/p>\n","protected":false},"author":141,"featured_media":65382,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[732],"class_list":["post-64095","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-core-java","tag-elasticsearch"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Elasticsearch for Java Developers: Elasticsearch from the command line - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"This article is part of our Academy Course titled Elasticsearch Tutorial for Java Developers. In this course, we provide a series of tutorials so that you\" \/>\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\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Elasticsearch for Java Developers: Elasticsearch from the command line - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"This article is part of our Academy Course titled Elasticsearch Tutorial for Java Developers. In this course, we provide a series of tutorials so that you\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.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=\"2017-02-27T17:00:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-11T08:15:30+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=\"Andrey Redko\" \/>\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=\"Andrey Redko\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"13 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html\"},\"author\":{\"name\":\"Andrey Redko\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/771a6504862edc45322776832cbce413\"},\"headline\":\"Elasticsearch for Java Developers: Elasticsearch from the command line\",\"datePublished\":\"2017-02-27T17:00:06+00:00\",\"dateModified\":\"2023-12-11T08:15:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html\"},\"wordCount\":2792,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2017\\\/04\\\/elastic-logo.png\",\"keywords\":[\"Elasticsearch\"],\"articleSection\":[\"Core Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html\",\"name\":\"Elasticsearch for Java Developers: Elasticsearch from the command line - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2017\\\/04\\\/elastic-logo.png\",\"datePublished\":\"2017-02-27T17:00:06+00:00\",\"dateModified\":\"2023-12-11T08:15:30+00:00\",\"description\":\"This article is part of our Academy Course titled Elasticsearch Tutorial for Java Developers. In this course, we provide a series of tutorials so that you\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.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\\\/2017\\\/02\\\/elasticsearch-java-developers-elasticsearch-command-line.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\":\"Core Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/core-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Elasticsearch for Java Developers: Elasticsearch from the command line\"}]},{\"@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\\\/771a6504862edc45322776832cbce413\",\"name\":\"Andrey Redko\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g\",\"caption\":\"Andrey Redko\"},\"description\":\"Andriy is a well-grounded software developer with more then 12 years of practical experience using Java\\\/EE, C#\\\/.NET, C++, Groovy, Ruby, functional programming (Scala), databases (MySQL, PostgreSQL, Oracle) and NoSQL solutions (MongoDB, Redis).\",\"sameAs\":[\"http:\\\/\\\/aredko.blogspot.com\\\/\",\"http:\\\/\\\/ca.linkedin.com\\\/in\\\/aredko\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/andrey-redko\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Elasticsearch for Java Developers: Elasticsearch from the command line - Java Code Geeks","description":"This article is part of our Academy Course titled Elasticsearch Tutorial for Java Developers. In this course, we provide a series of tutorials so that you","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\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html","og_locale":"en_US","og_type":"article","og_title":"Elasticsearch for Java Developers: Elasticsearch from the command line - Java Code Geeks","og_description":"This article is part of our Academy Course titled Elasticsearch Tutorial for Java Developers. In this course, we provide a series of tutorials so that you","og_url":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-02-27T17:00:06+00:00","article_modified_time":"2023-12-11T08:15:30+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":"Andrey Redko","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Andrey Redko","Est. reading time":"13 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html"},"author":{"name":"Andrey Redko","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/771a6504862edc45322776832cbce413"},"headline":"Elasticsearch for Java Developers: Elasticsearch from the command line","datePublished":"2017-02-27T17:00:06+00:00","dateModified":"2023-12-11T08:15:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html"},"wordCount":2792,"commentCount":2,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/elastic-logo.png","keywords":["Elasticsearch"],"articleSection":["Core Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html","url":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html","name":"Elasticsearch for Java Developers: Elasticsearch from the command line - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/elastic-logo.png","datePublished":"2017-02-27T17:00:06+00:00","dateModified":"2023-12-11T08:15:30+00:00","description":"This article is part of our Academy Course titled Elasticsearch Tutorial for Java Developers. In this course, we provide a series of tutorials so that you","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.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\/2017\/02\/elasticsearch-java-developers-elasticsearch-command-line.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":"Core Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/core-java"},{"@type":"ListItem","position":4,"name":"Elasticsearch for Java Developers: Elasticsearch from the command line"}]},{"@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\/771a6504862edc45322776832cbce413","name":"Andrey Redko","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/16419ce8394173028eddaeb992859862bab50cfcf74589fa9bb9a3dd8bb27518?s=96&d=mm&r=g","caption":"Andrey Redko"},"description":"Andriy is a well-grounded software developer with more then 12 years of practical experience using Java\/EE, C#\/.NET, C++, Groovy, Ruby, functional programming (Scala), databases (MySQL, PostgreSQL, Oracle) and NoSQL solutions (MongoDB, Redis).","sameAs":["http:\/\/aredko.blogspot.com\/","http:\/\/ca.linkedin.com\/in\/aredko"],"url":"https:\/\/www.javacodegeeks.com\/author\/andrey-redko"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/64095","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\/141"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=64095"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/64095\/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=64095"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=64095"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=64095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}