Getting Started with Elasticsearch: Installation and Basic Operations
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"
}
}
}
}