The quickest way to get used to something is to use it, so we need to get Elasticsearch up and running so we can use it and learn it.

The fastest way to get started with Elasticsearch is to get a free 14-day trial of Elasticsearch in the cloud.

Instead of doing this, we will run Elasticsearch locally as per the official documentation.

Install the Elasticsearch

The installation steps are as follows:

  1. Download Elasticsearch zip package:

Linux: elasticsearch 7.11.1 – Linux – x86_64. Tar. Gz

The curl - L - O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-linux-x86_64.tar.gzCopy the code

MacOS: elasticsearch – 7.11.1 – Darwin – x86_64. Tar. Gz

The curl - L - O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.11.1-darwin-x86_64.tar.gzCopy the code

Windows: elasticsearch – 7.11.1 – Windows – x86_64. Zip

  1. Unzip files:

Linux:

Tar - XVF elasticsearch 7.11.1 - Linux - x86_64. Tar. GzCopy the code

macOS:

The tar - XVF elasticsearch 7.11.1 - Darwin - x86_64. Tar. GzCopy the code

Windows PowerShell:

Expand-Archive elasticsearch-7.11.1-windows-x86_64.zip
Copy the code
  1. From the decompressionbinStart Elasticsearch in directory:

Linux and macOS:

cdElasticsearch - 7.11.1 / bin/elasticsearchCopy the code

Windows:

cdElasticsearch - 7.11.1 \ bin \ elasticsearch batCopy the code

A single-node Elasticsearch cluster is now running.

  1. Start two more instances of Elasticsearch. You need to specify a unique data and log path for each node.

Linux and macOS:

./elasticsearch -Epath.data=data2 -Epath.logs=log2
./elasticsearch -Epath.data=data3 -Epath.logs=log3
Copy the code

Windows:

.\elasticsearch.bat -E path.data=data2 -E path.logs=log2
.\elasticsearch.bat -E path.data=data3 -E path.logs=log3
Copy the code

Additional nodes will be assigned unique ids. For all three nodes running locally, they will automatically join the cluster with the first node.

  1. usecat health APIVerify that your three-node cluster is running. thiscat APIReturns information about clusters and indexes in a more readable format than native JSON.

You can directly interact with the cluster by submitting HTTP requests through the Elasticsearch REST API. If you have Kibana installed and running, you can also open Kibana and submit a request via the Dev Console.

When you’re ready to start using Elasticsearch in your own applications, you might want to check out the Elasticsearch language client.

GET /_cat/health? v=true
Copy the code

The response should indicate that the status of the Elasticsearch cluster is green and that it has three nodes:

epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time Active_shards_percent 1565052807 00:53:27 ElasticSearch Green 3 3 6 3 00 00-100.0%Copy the code

If there is only one Instance of Elasticsearch, the cluster status remains yellow. A single-node cluster is fully functional, but data cannot be copied to another node to provide flexibility. If the cluster status is green, the replica fragments must be available. If the cluster status is red, some data is unavailable.

You can use the REST API to do this. You can also use the curl command to do this.

The standard curl command format is as follows:

curl -X<VERB> '
      
       ://
       
        :
        
         /
         
          ? 
          
           '
          
         
        
       
       -d '<BODY>'
Copy the code

This example uses the following variables:

<VERB>

Appropriate HTTP method or operation. For example, GET, POST, PUT, HEAD, or DELETE.

<PROTOCOL>

HTTP or HTTPS. Use the latter if you have an HTTPS proxy before Elasticsearch or if you are using Elasticsearch security features to encrypt HTTP traffic.

<HOST>

Host name of any node in the Elasticsearch cluster. Or use localhost for nodes on the local machine.

<PORT>

Port for running the Elasticsearch HTTP service. The default port is 9200.

<PATH>

API path, which can contain multiple parts, such as _cluster/stats or _nodes/stats/ JVM.

<QUERY_STRING>

Some optional query string parameters. For example,? Pretty will print the JSON response to make it easier to read.

<BODY>

Json-encoded request body (if necessary).

If you have Elasticsearch security enabled, you must provide a valid username (and password) for authenticating the runtime API. For example, use the -u or –u cURL command argument. For details on the security permissions required to run each API, see REST API.

Elasticsearch responds to each API request with an HTTP status code, such as 200 OK. In addition to the HEAD request, it also returns a JSON-encoded response body.

Now you can get Elasticsearch up and running and use a simple API to check the status of Elasticsearch and the standard RESTful API format.

JDK 8 does not work with Elasticsearch higher versions:

Warning: with JDK 8 on Windows, Elasticsearch may be unable to derive correct
  ergonomic settings due to a JDK issue (JDK-8074459). Please use a newer
  version of Java.
Warning: MaxDirectMemorySize may have been miscalculated due to JDK-8074459.
  Please use a newer version of Java or set MaxDirectMemorySize explicitly.
Copy the code

When prompted, you can ignore it, configure the MaxDirectMemorySize parameter as prompted, or install Java 11 as prompted.

Elasticsearch has a port of 9200. If you go to http://localhost:9200 directly via Postman, you can see that 200 OK is returned, and the following response body:

{
    "name": "XXXXX"."cluster_name": "elasticsearch"."cluster_uuid": "6rV0qTnBQIyyTo85ZAOK-w"."version": {
        "number": "7.11.1"."build_flavor": "default"."build_type": "zip"."build_hash": "ff17057114c2199c9c1bbecc727003a907c0db7a"."build_date": "The 2021-02-15 T13:44:09. 394032 z"."build_snapshot": false."lucene_version": "8.7.0"."minimum_wire_compatibility_version": "6.8.0"."minimum_index_compatibility_version": "6.0.0 - beta1"
    },
    "tagline": "You Know, for Search"
}
Copy the code

If the above response body is displayed, Elasticsearch is running successfully.

For details on how to install Elasticsearch, see the Elasticsearch Documentation for more details.

Welcome to my blog: The Border city of A-woo

Welcome to pay attention to my public number: A woo programming