Elasticsearch 5.2.1Cluster 搭建

1.安装java

  • cd ~
  • wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u73-b02/jdk-8u73-linux-x64.rpm"

2.安装elasticsearch:

       现在一台机器上解压:

        tar zxvf elasticsearch-5.2.1.tar.gz

        修改配置文件:

   network.host:对应机器的ip

   cluster.name: production

         node.name: ${HOSTNAME}

         discovery.zen.ping.unicast.hosts: ["node01", "node02", "node03"]

          保存启动

          配置好的直接拷贝到另外两台机器记得修改ip

3.检查:curl -XGET 'http://localhost:9200/_cluster/state?pretty'

成功:

4.相关配置:

启用内存锁定:

bootstrap.mlockall: true

计算集群中文档的数量:
GET /_count
{
"query": {
"match_all": {}
}
}
索引雇员文档:
PUT /megacorp/employee/1
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}

PUT /megacorp/employee/2
{
"first_name" : "Jane",
"last_name" : "Smith",
"age" : 32,
"about" : "I like to collect rock albums",
"interests": [ "music" ]
}

PUT /megacorp/employee/3
{
"first_name" : "Douglas",
"last_name" : "Fir",
"age" : 35,
"about": "I like to build cabinets",
"interests": [ "forestry" ]
}
检索到单个雇员的数据:
GET /megacorp/employee/1
GET /megacorp/employee/_search
查询字符串 (_query-string_) 搜索:

GET /megacorp/employee/_search?q=last_name:Smith
使用查询表达式搜索:(即席搜索)
GET /megacorp/employee/_search
{
"query" : {
"match" : {
"last_name" : "Smith"
}
}
}
更复杂的搜索:
GET /megacorp/employee/_search
{
"query" : {
"bool": {
"must": {
"match" : {
"last_name" : "smith"
}
},
"filter": {
"range" : {
"age" : { "gt" : 30 }
}
}
}
}
}
稍微高级点儿的全文搜索:

GET /megacorp/employee/_search
{
"query" : {
"match" : {
"about" : "rock climbing"
}
}
}

精确匹配一系列单词或者短语:

 
原文地址:https://www.cnblogs.com/Jt00/p/7149194.html