{"id":5353,"date":"2018-09-27T02:03:15","date_gmt":"2018-09-27T02:03:15","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=5353"},"modified":"2025-05-04T06:08:23","modified_gmt":"2025-05-04T06:08:23","slug":"what-are-the-method-to-interact-with-elastic-search","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/what-are-the-method-to-interact-with-elastic-search\/","title":{"rendered":"What are the method to interact with Elastic Search?"},"content":{"rendered":"<p>Elasticsearch provides official clients for several languages\u2014Groovy, JavaScript, .NET, PHP, Perl, Python, and Ruby\u2014and there are numerous community-provided clients and integrations, all of which can be found in<\/p>\n<p>There are various following methods which is available&#8230;<\/p>\n<ul>\n<li>Java REST Client<\/li>\n<li>Java API<\/li>\n<li>JavaScript API<\/li>\n<li>Groovy API<\/li>\n<li>.NET API<\/li>\n<li>PHP API<\/li>\n<li>Perl API<\/li>\n<li>Python API<\/li>\n<li>Ruby API<\/li>\n<li>Community Contributed Clients<\/li>\n<\/ul>\n<p><strong>Details can be found here.<\/strong><br \/>\nhttps:\/\/www.elastic.co\/guide\/en\/elasticsearch\/client\/index.html<\/p>\n<p><strong>RESTful API with JSON over HTTPedit<\/strong><br \/>\nAll other languages can communicate with Elasticsearch over port 9200 using a RESTful API, accessible with your favorite web client.<\/p>\n<p><strong>A request to Elasticsearch consists of the same parts as any HTTP request:<\/strong><\/p>\n<p>[code]curl -X&lt;VERB&gt; &#8216;&lt;PROTOCOL&gt;:\/\/&lt;HOST&gt;:&lt;PORT&gt;\/&lt;PATH&gt;?&lt;QUERY_STRING&gt;&#8217; -d &#8216;&lt;BODY&gt;'[\/code]<\/p>\n<p><strong>The parts marked with&nbsp;&lt; &gt;&nbsp;above are:<\/strong><\/p>\n<div>\n<table border=\"0\" cellpadding=\"4px\">\n<colgroup>\n<col>\n<col> <\/colgroup>\n<tbody valign=\"top\">\n<tr>\n<td valign=\"top\">VERB<\/td>\n<td valign=\"top\">The appropriate HTTP&nbsp;<em>method<\/em>&nbsp;or&nbsp;<em>verb<\/em>:&nbsp;GET,&nbsp;POST,&nbsp;PUT,&nbsp;HEAD, or&nbsp;DELETE.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">PROTOCOL<\/td>\n<td valign=\"top\">Either&nbsp;http&nbsp;or&nbsp;https&nbsp;(if you have an&nbsp;https&nbsp;proxy in front of Elasticsearch.)<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">HOST<\/td>\n<td valign=\"top\">The hostname of any node in your Elasticsearch cluster, or&nbsp;localhost&nbsp;for a node on your local machine.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">PORT<\/td>\n<td valign=\"top\">The port running the Elasticsearch HTTP service, which defaults to&nbsp;9200.<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">PATH<\/td>\n<td valign=\"top\">API Endpoint (for example&nbsp;_count&nbsp;will return the number of documents in the cluster). Path may contain multiple components, such as&nbsp;_cluster\/stats&nbsp;or&nbsp;_nodes\/stats\/jvm<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">QUERY_STRING<\/td>\n<td valign=\"top\">Any optional query-string parameters (for example&nbsp;?pretty&nbsp;will&nbsp;<em>pretty-print<\/em>&nbsp;the JSON response to make it easier to read.)<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\">BODY<\/td>\n<td valign=\"top\">A JSON-encoded request body (if the request needs one.)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><strong>JAVA API<\/strong><\/p>\n<p><strong>In case of Java based, Elasticsearch has been deleloped using Java so Elasticsearch comes with two built-in clients that you can use in your code:<\/strong><\/p>\n<p><strong>Node client<\/strong><br \/>\nThe node client joins a local cluster as a non data node. In other words, it doesn\u2019t hold any data itself, but it knows what data lives on which node in the cluster, and can forward requests directly to the correct node.<\/p>\n<p><strong>Transport client<\/strong><br \/>\nThe lighter-weight transport client can be used to send requests to a remote cluster. It doesn\u2019t join the cluster itself, but simply forwards requests to a node in the cluster.<\/p>\n<p>Both Java clients talk to the cluster over port 9300, using the native Elasticsearch transport protocol. The nodes in the cluster also communicate with each other over port 9300. If this port is not open, your nodes will not be able to form a cluster.<\/p>\n<p><strong>Difference between Transport client Vs Node client<\/strong><br \/>\nThe transport client acts as a communication layer between the cluster and your application. It knows the API and can automatically round-robin between nodes, sniff the cluster for you, and more. But it is external to the cluster, similar to the REST clients.<\/p>\n<p>The node client, on the other hand, is actually a node within the cluster (but does not hold data, and cannot become master). Because it is a node, it knows the entire cluster state (where all the nodes reside, which shards live in which nodes, and so forth). This means it can execute APIs with one less network hop.<\/p>\n<p><strong>Uses-cases for Transport client and Node client<\/strong><br \/>\nThe transport client is ideal if you want to decouple your application from the cluster. For example, if your application quickly creates and destroys connections to the cluster,a transport client is much &#8220;lighter&#8221; than a node client, since it is not part of a cluster.<\/p>\n<p>Similarly, if you need to create thousands of connections, you don\u2019t want to have thousands of node clients join the cluster. The TC will be a better choice.<\/p>\n<p>On the flipside, if you need only a few long-lived, persistent connection objects to the cluster, a node client can be a bit more efficient since it knows the cluster layout. But it ties your application into the cluster, so it may pose problems from a firewall perspective.<\/p>\n<p><strong>Good Read can be found here as well<\/strong><br \/>\nhttps:\/\/stackoverflow.com\/questions\/15398861\/elasticsearch-nodebuilder-vs-tranportclient<\/p>\n<p><strong>Elasticsearch transport client example<\/strong><br \/>\nhttps:\/\/www.elastic.co\/guide\/en\/elasticsearch\/client\/java-api\/current\/transport-client.html<br \/>\nhttps:\/\/www.programcreek.com\/java-api-examples\/?api=org.elasticsearch.client.transport.TransportClient<br \/>\nhttps:\/\/www.elastic.co\/guide\/en\/elasticsearch\/client\/java-api\/current\/transport-client.html<\/p>\n<p><strong>Elasticsearch node client example<\/strong><br \/>\nhttps:\/\/www.programcreek.com\/java-api-examples\/?api=org.elasticsearch.node.NodeBuilder<br \/>\nhttps:\/\/github.com\/elastic\/elasticsearch-js<\/p>\n<p><strong>Reference<\/strong><br \/>\nhttps:\/\/www.elastic.co\/guide\/en\/elasticsearch\/client\/index.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Elasticsearch provides official clients for several languages\u2014Groovy, JavaScript, .NET, PHP, Perl, Python, and Ruby\u2014and there are numerous community-provided clients and integrations, all of which can be found in There are various following methods which is available&#8230; Java REST Client Java API JavaScript API Groovy API .NET API PHP API Perl API Python API Ruby API&#8230;<\/p>\n","protected":false},"author":1,"featured_media":8137,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[5936],"tags":[1886,5057,5056,4666,1543,5058],"class_list":["post-5353","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-elastic","tag-client","tag-elastic","tag-elastic-search","tag-elasticsearch","tag-node","tag-transport"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=5353"}],"version-history":[{"count":4,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5353\/revisions"}],"predecessor-version":[{"id":8138,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/5353\/revisions\/8138"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/8137"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=5353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=5353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=5353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}