Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Getting Started with Elasticsearch: Installation and Basic Operations

Tech Jul 24 1

System Requirements

Component Version
Operating System MacOS
Elasticsearch 6.3.0
Visualization Plugin Head

Installation Process

Single Node Setup

Download Elasticsearch from the official website or alternative sources. The current stable version is available at:

https://www.elastic.co/downloads/elasticsearch

For previous versions, visit:

https://www.elastic.co/downloads/past-releases

After downloading, execute the elasticsearch binary from the bin directory. Verify the installation by accessing:

http://localhost:9200/

Head Plugin Configuration

The Head plugin requires Node.js. After installing Node.js, configure Elasticsearch by adding these lines to elasticsearch.yml:


http.cors.enabled: true
http.cors.allow-origin: "*"

Start the Head plugin with these commands:


npm install phantomjs-prebuilt@2.1.15 --ignore-scripts
npm install
npm run start

Access the interface at:

http://localhost:9100

Cluster Configuration

For a distributed setup, create copies of the Elasticsearch installation. Configure each node's elasticsearch.yml with:


cluster.name: my_cluster
node.name: node_1
network.host: 127.0.0.1
http.port: 8200
discovery.zen.ping.unicast.hosts: ["127.0.0.1"]

Core Concepts

Indexing Structure

Elasticsearch RDBMS
Index Database
Type (deprecated) Table
Document Row

Sharding and Replication

Each index consists of multiple shards (Lucene indices). Replicas provide redundancy by copying shards.

Configuration Options


cluster.name: production
node.name: primary_node
node.master: true
node.data: true
network.host: 0.0.0.0
http.port: 9200
discovery.zen.minimum_master_nodes: 1

Basic Operations

Index Management


PUT /my_index
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 1
  }
}

Document Operations

Create document with specified ID:

PUT /index/type/doc_id

Create document with auto-generated ID:

POST /index/type

Update document:


POST /index/type/doc_id/_update
{
  "doc": {
    "field": "new_value"
  }
}

Delete document:

DELETE /index/type/doc_id

Search Queries

Basic search:


GET /index/type/_search
{
  "query": {
    "match": {
      "field": "value"
    }
  }
}

Aggregation queries:


GET /index/type/_search
{
  "aggs": {
    "group_by_field": {
      "terms": {
        "field": "category"
      }
    }
  }
}

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.