How to Install Elasticsearch (Single Node Cluster) on CentOS & Ubuntu
转载自: http://tecadmin.net/install-elasticsearch-on-linux/#
Elasticsearch is flexible and powerful open source, distributed real-time search and analytic engine. Using a simple set of APIs, it provides the ability for full-text search. Elastic search is freely available under the Apache 2 license, which provides most flexibility.
This tutorial will help you to setup Elasticsearch single node cluster on CentOS, Red Hat, Ubuntu, Debian and LinuxMint systems.
1. Verify Java
Java is the primary requirement for installing Elasticsearch. So make sure you have Java installed on your system.
# java -version java version "1.8.0_31" Java(TM) SE Runtime Environment (build 1.8.0_31-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.31-b07, mixed mode)
If you don’t have Java installed on your system, use one of following link to install it first.
2. Download Elasticsearch Archive
Now download the latest Elasticsearch archive from its official download page. At the time of last update of this article Elasticsearch 2.3.1 version is latest version available to download.
$ /tmp $ wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-2.3.1.tar.gz
Now extract downloaded Elasticsearch archive on your system.
$ tar xzf elasticsearch-2.3.1.tar.gz
3. Configure Elasticsearch
Now we need to setup Elasticsearch cluster and node name. Elasticsearch uses “elasticsearch” as default cluster name, We recommend to change it as per your setup.
$ mv elasticsearch-2.3.1 /usr/share/elasticsearch $ cd /usr/share/elasticsearch
To change cluster named edit config/elasticsearch.yml file and update following values. Node names are dynamically generated, but to keep a fixed user-friendly name change it also. You may also need to change network host to access elasticsearch from remote hosts.
$ vim config/elasticsearch.yml
network.host: 192.168.10.100 cluster.name: TecAdmin_Cluster1 node.name: "California DataCenter"
4. Install Elasticsearch-Head Plugin
elasticsearch-head is a web front end for browsing and interacting with an Elastic Search cluster. Use the following command to install it.
$ bin/plugin install mobz/elasticsearch-head
5. Starting Elasticsearch Cluster
As the Elasticsearch setup is completed. Let the start Elasticsearch cluster using following command.
$ ./bin/elasticsearch &
6. Verify Setup
You have all done, just need to verify setup. Elasticsearch works on port default port 9200, open your browser to point your server on port 9200, You will find some thing like below output
http://localhost:9200/_plugin/head/
http://svt1.tecadmin.net:9200/
7. Basic Examples of Elasticsearch Uses
Following examples will help you to add, fetch and search data in Elasticsearch cluster.
Creating Bucket
curl -XPUT http://localhost:9200/mybucket
Output:
{"acknowledged":true}
Adding Data to Elasticsearch
Use following commands to add some data in Elasticsearch.
Command 1:
curl -XPUT 'http://localhost:9200/mybucket/user/johny' -d '{ "name" : "Rahul Kumar" }'
Output:
{"_index":"mybucket","_type":"user","_id":"johny","_version":1,"created":true}
Command 2:
curl -XPUT 'http://localhost:9200/mybucket/post/1' -d ' { "user": "Rahul", "postDate": "01-15-2015", "body": "This is Demo Post 1 in Elasticsearch" , "title": "Demo Post 1" }'
Output:
{"_index":"mybucket","_type":"post","_id":"1","_version":1,"created":true}
Command 3:
curl -XPUT 'http://localhost:9200/mybucket/post/2' -d ' { "user": "TecAdmin", "postDate": "01-15-2015", "body": "This is Demo Post 2 in Elasticsearch" , "title": "Demo Post 2" }'
Output:
{"_index":"mybucket","_type":"post","_id":"2","_version":1,"created":true}
Fetching Data from Elasticsearch
Use following command to GET data from ElasticSearch and read the output.
curl -XGET 'http://localhost:9200/mybucket/user/johny?pretty=true' curl -XGET 'http://localhost:9200/mybucket/post/1?pretty=true' curl -XGET 'http://localhost:9200/mybucket/post/2?pretty=true'
Searching in Elasticsearch
Use following command to search data from elastic search. Below command will search all data associated with user johny.
curl 'http://localhost:9200/mybucket/post/_search?q=user:TecAdmin&pretty=true'
Output:
{ "took" : 145, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 0.30685282, "hits" : [ { "_index" : "mybucket", "_type" : "post", "_id" : "2", "_score" : 0.30685282, "_source": { "user": "TecAdmin", "postDate": "01-15-2015", "body": "This is Demo Post 2 in Elasticsearch" , "title": "Demo Post 2" } } ] } }
Congratulation’s! You have successfully configured elasticsearch single node cluster on your Linux system.
相关推荐
另外一部分,则需要先做聚类、分类处理,将聚合出的分类结果存入ES集群的聚类索引中。数据处理层的聚合结果存入ES中的指定索引,同时将每个聚合主题相关的数据存入每个document下面的某个field下。