Well,不要刷屏了

社区日报 第102期 (2017-11-16)

1.BM25 ES现在使用的Lucene相关性算法
http://t.cn/RjSSp1T
2.通过Search Guard 为Elasticsearch 进行安全加固。
https://elasticsearch.cn/article/350
3.一个将ES查询结果以PDF,HTML或CSV形式导出的ES插件
http://t.cn/RjJsItO
4、Elastic Meetup 广州交流会 
https://elasticsearch.cn/article/364 
 
编辑:金桥
归档:https://elasticsearch.cn/article/382
订阅:https://tinyletter.com/elastic-daily
继续阅读 »
1.BM25 ES现在使用的Lucene相关性算法
http://t.cn/RjSSp1T
2.通过Search Guard 为Elasticsearch 进行安全加固。
https://elasticsearch.cn/article/350
3.一个将ES查询结果以PDF,HTML或CSV形式导出的ES插件
http://t.cn/RjJsItO
4、Elastic Meetup 广州交流会 
https://elasticsearch.cn/article/364 
 
编辑:金桥
归档:https://elasticsearch.cn/article/382
订阅:https://tinyletter.com/elastic-daily 收起阅读 »

Elasticsearch Java API 索引的增删改查(二)

本节介绍以下 CRUD API:

 单文档  APIs

多文档 APIs

Multi Get API Bulk API

注意:所有的单文档的CRUD API,index参数只能接受单一的索引库名称,或者是一个指向单一索引库的alias。

Index API

Index API 允许我们存储一个JSON格式的文档,使数据可以被搜索。文档通过index、type、id唯一确定。我们可以自己提供一个id,或者也使用Index API 为我们自动生成一个。

这里有几种不同的方式来产生JSON格式的文档(document):

  • 手动方式,使用原生的byte[]或者String
  • 使用Map方式,会自动转换成与之等价的JSON
  • 使用第三方库来序列化beans,如Jackson
  • 使用内置的帮助类 XContentFactory.jsonBuilder()

手动方式

数据格式

String json = "{" +
        "\"user\":\"kimchy\"," +
        "\"postDate\":\"2013-01-30\"," +
        "\"message\":\"trying out Elasticsearch\"" +
    "}";
实例
/**  
 * 手动生成JSON  
 */  
@Test  
public void CreateJSON(){  
      
    String json = "{" +  
            "\"user\":\"fendo\"," +  
            "\"postDate\":\"2013-01-30\"," +  
            "\"message\":\"Hell word\"" +  
        "}";  
      
    IndexResponse response = client.prepareIndex("fendo", "fendodate")  
            .setSource(json)  
            .get();  
    System.out.println(response.getResult());  
      
}  

  Map方式

Map是key:value数据类型,可以代表json结构.

Map<String, Object> json = new HashMap<String, Object>();
json.put("user","kimchy");
json.put("postDate",new Date());
json.put("message","trying out Elasticsearch");
实例
 /**  
 * 使用集合  
 */  
@Test  
public void CreateList(){  
      
    Map<String, Object> json = new HashMap<String, Object>();  
    json.put("user","kimchy");  
    json.put("postDate","2013-01-30");  
    json.put("message","trying out Elasticsearch");  
      
    IndexResponse response = client.prepareIndex("fendo", "fendodate")  
            .setSource(json)  
            .get();  
    System.out.println(response.getResult());  
      
}  

  序列化方式

ElasticSearch已经使用了jackson,可以直接使用它把javabean转为json.

import com.fasterxml.jackson.databind.*;

// instance a json mapper
ObjectMapper mapper = new ObjectMapper(); // create once, reuse

// generate json
byte[] json = mapper.writeValueAsBytes(yourbeaninstance);
实例
/**  
 * 使用JACKSON序列化  
 * @throws Exception  
 */  
@Test  
public void CreateJACKSON() throws Exception{  
      
    CsdnBlog csdn=new CsdnBlog();  
    csdn.setAuthor("fendo");  
    csdn.setContent("这是JAVA书籍");  
    csdn.setTag("C");  
    csdn.setView("100");  
    csdn.setTitile("编程");  
    csdn.setDate(new Date().toString());  
      
    // instance a json mapper  
    ObjectMapper mapper = new ObjectMapper(); // create once, reuse  

    // generate json  
    byte[] json = mapper.writeValueAsBytes(csdn);  
      
    IndexResponse response = client.prepareIndex("fendo", "fendodate")  
            .setSource(json)  
            .get();  
    System.out.println(response.getResult());  
}  

  XContentBuilder帮助类方式

ElasticSearch提供了一个内置的帮助类XContentBuilder来产生JSON文档

// Index name
String _index = response.getIndex();
// Type name
String _type = response.getType();
// Document ID (generated or not)
String _id = response.getId();
// Version (if it's the first time you index this document, you will get: 1)
long _version = response.getVersion();
// status has stored current instance statement.
RestStatus status = response.status();
实例
/**  
 * 使用ElasticSearch 帮助类  
 * @throws IOException   
 */  
@Test  
public void CreateXContentBuilder() throws IOException{  
      
    XContentBuilder builder = XContentFactory.jsonBuilder()  
            .startObject()  
                .field("user", "ccse")  
                .field("postDate", new Date())  
                .field("message", "this is Elasticsearch")  
            .endObject();  
      
    IndexResponse response = client.prepareIndex("fendo", "fendodata").setSource(builder).get();  
    System.out.println("创建成功!");  
      
      
}  

综合实例

 
import java.io.IOException;  
import java.net.InetAddress;  
import java.net.UnknownHostException;  
import java.util.Date;  
import java.util.HashMap;  
import java.util.Map;  
  
import org.elasticsearch.action.index.IndexResponse;  
import org.elasticsearch.client.transport.TransportClient;  
import org.elasticsearch.common.settings.Settings;  
import org.elasticsearch.common.transport.InetSocketTransportAddress;  
import org.elasticsearch.common.xcontent.XContentBuilder;  
import org.elasticsearch.common.xcontent.XContentFactory;  
import org.elasticsearch.transport.client.PreBuiltTransportClient;  
import org.junit.Before;  
import org.junit.Test;  
  
import com.fasterxml.jackson.core.JsonProcessingException;  
import com.fasterxml.jackson.databind.ObjectMapper;  
  
public class CreateIndex {  
  
    private TransportClient client;  
      
    @Before  
    public void getClient() throws Exception{  
        //设置集群名称  
        Settings settings = Settings.builder().put("cluster.name", "my-application").build();// 集群名  
        //创建client  
        client  = new PreBuiltTransportClient(settings)  
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));  
    }  
      
    /**  
     * 手动生成JSON  
     */  
    @Test  
    public void CreateJSON(){  
          
        String json = "{" +  
                "\"user\":\"fendo\"," +  
                "\"postDate\":\"2013-01-30\"," +  
                "\"message\":\"Hell word\"" +  
            "}";  
          
        IndexResponse response = client.prepareIndex("fendo", "fendodate")  
                .setSource(json)  
                .get();  
        System.out.println(response.getResult());  
          
    }  
      
      
    /**  
     * 使用集合  
     */  
    @Test  
    public void CreateList(){  
          
        Map<String, Object> json = new HashMap<String, Object>();  
        json.put("user","kimchy");  
        json.put("postDate","2013-01-30");  
        json.put("message","trying out Elasticsearch");  
          
        IndexResponse response = client.prepareIndex("fendo", "fendodate")  
                .setSource(json)  
                .get();  
        System.out.println(response.getResult());  
          
    }  
      
    /**  
     * 使用JACKSON序列化  
     * @throws Exception  
     */  
    @Test  
    public void CreateJACKSON() throws Exception{  
          
        CsdnBlog csdn=new CsdnBlog();  
        csdn.setAuthor("fendo");  
        csdn.setContent("这是JAVA书籍");  
        csdn.setTag("C");  
        csdn.setView("100");  
        csdn.setTitile("编程");  
        csdn.setDate(new Date().toString());  
          
        // instance a json mapper  
        ObjectMapper mapper = new ObjectMapper(); // create once, reuse  
  
        // generate json  
        byte[] json = mapper.writeValueAsBytes(csdn);  
          
        IndexResponse response = client.prepareIndex("fendo", "fendodate")  
                .setSource(json)  
                .get();  
        System.out.println(response.getResult());  
    }  
      
    /**  
     * 使用ElasticSearch 帮助类  
     * @throws IOException   
     */  
    @Test  
    public void CreateXContentBuilder() throws IOException{  
          
        XContentBuilder builder = XContentFactory.jsonBuilder()  
                .startObject()  
                    .field("user", "ccse")  
                    .field("postDate", new Date())  
                    .field("message", "this is Elasticsearch")  
                .endObject();  
          
        IndexResponse response = client.prepareIndex("fendo", "fendodata").setSource(builder).get();  
        System.out.println("创建成功!");  
          
          
    }  
      
}  

你还可以通过startArray(string)和endArray()方法添加数组。.field()方法可以接受多种对象类型。你可以给它传递数字、日期、甚至其他XContentBuilder对象。

Get API

根据id查看文档:

GetResponse response = client.prepareGet("twitter", "tweet", "1").get();

更多请查看 rest get API 文档

配置线程

operationThreaded 设置为 true 是在不同的线程里执行此次操作

下面的例子是operationThreaded 设置为 false

GetResponse response = client.prepareGet("twitter", "tweet", "1")
        .setOperationThreaded(false)
        .get();

Delete API

根据ID删除:

DeleteResponse response = client.prepareDelete("twitter", "tweet", "1").get();

更多请查看 delete API 文档

配置线程

operationThreaded 设置为 true 是在不同的线程里执行此次操作

下面的例子是operationThreaded 设置为 false

GetResponse response = client.prepareGet("twitter", "tweet", "1")
        .setOperationThreaded(false)
        .get();
DeleteResponse response = client.prepareDelete("twitter", "tweet", "1")
        .setOperationThreaded(false)
        .get();

Delete By Query API

通过查询条件删除

BulkByScrollResponse response =
    DeleteByQueryAction.INSTANCE.newRequestBuilder(client)
        .filter(QueryBuilders.matchQuery("gender", "male")) //查询条件
        .source("persons") //index(索引名)
        .get();  //执行

long deleted = response.getDeleted(); //删除文档的数量

如果需要执行的时间比较长,可以使用异步的方式处理,结果在回调里面获取

DeleteByQueryAction.INSTANCE.newRequestBuilder(client)
    .filter(QueryBuilders.matchQuery("gender", "male"))      //查询            
    .source("persons")                //index(索引名)                                    
    .execute(new ActionListener<BulkByScrollResponse>() {     //回调监听     
        @Override
        public void onResponse(BulkByScrollResponse response) {
            long deleted = response.getDeleted();   //删除文档的数量                 
        }
        @Override
        public void onFailure(Exception e) {
            // Handle the exception
        }
    });

Update API

有两种方式更新索引:

  • 创建 UpdateRequest,通过client发送;
  • 使用 prepareUpdate() 方法;

使用UpdateRequest

UpdateRequest updateRequest = new UpdateRequest();
updateRequest.index("index");
updateRequest.type("type");
updateRequest.id("1");
updateRequest.doc(jsonBuilder()
        .startObject()
            .field("gender", "male")
        .endObject());
client.update(updateRequest).get();

使用 prepareUpdate() 方法

这里官方的示例有问题,new Script()参数错误,所以一下代码是我自己写的(2017/11/10)

client.prepareUpdate("ttl", "doc", "1")
        .setScript(new Script("ctx._source.gender = \"male\""  ,ScriptService.ScriptType.INLINE, null, null))//脚本可以是本地文件存储的,如果使用文件存储的脚本,需要设置 ScriptService.ScriptType.FILE 
        .get();

client.prepareUpdate("ttl", "doc", "1")
        .setDoc(jsonBuilder()   //合并到现有文档
            .startObject()
                .field("gender", "male")
            .endObject())
        .get();

Update by script

使用脚本更新文档 

UpdateRequest updateRequest = new UpdateRequest("ttl", "doc", "1")
        .script(new Script("ctx._source.gender = \"male\""));
client.update(updateRequest).get();

Update by merging documents

合并文档

UpdateRequest updateRequest = new UpdateRequest("index", "type", "1")
        .doc(jsonBuilder()
            .startObject()
                .field("gender", "male")
            .endObject());
client.update(updateRequest).get();

Upsert

更新插入,如果存在文档就更新,如果不存在就插入

IndexRequest indexRequest = new IndexRequest("index", "type", "1")
        .source(jsonBuilder()
            .startObject()
                .field("name", "Joe Smith")
                .field("gender", "male")
            .endObject());
UpdateRequest updateRequest = new UpdateRequest("index", "type", "1")
        .doc(jsonBuilder()
            .startObject()
                .field("gender", "male")
            .endObject())
        .upsert(indexRequest); //如果不存在此文档 ,就增加 `indexRequest`
client.update(updateRequest).get();

如果 index/type/1 存在,类似下面的文档:

{
    "name"  : "Joe Dalton",
    "gender": "male"        
}

如果不存在,会插入新的文档:

{
    "name" : "Joe Smith",
    "gender": "male"
}

Multi Get API

一次获取多个文档

MultiGetResponse multiGetItemResponses = client.prepareMultiGet()
    .add("twitter", "tweet", "1") //一个id的方式
    .add("twitter", "tweet", "2", "3", "4") //多个id的方式
    .add("another", "type", "foo")  //可以从另外一个索引获取
    .get();

for (MultiGetItemResponse itemResponse : multiGetItemResponses) { //迭代返回值
    GetResponse response = itemResponse.getResponse();
    if (response.isExists()) {      //判断是否存在                
        String json = response.getSourceAsString(); //_source 字段
    }
}

更多请浏览REST multi get 文档

Bulk API

Bulk API,批量插入:

import static org.elasticsearch.common.xcontent.XContentFactory.*;
BulkRequestBuilder bulkRequest = client.prepareBulk();

// either use client#prepare, or use Requests# to directly build index/delete requests
bulkRequest.add(client.prepareIndex("twitter", "tweet", "1")
        .setSource(jsonBuilder()
                    .startObject()
                        .field("user", "kimchy")
                        .field("postDate", new Date())
                        .field("message", "trying out Elasticsearch")
                    .endObject()
                  )
        );

bulkRequest.add(client.prepareIndex("twitter", "tweet", "2")
        .setSource(jsonBuilder()
                    .startObject()
                        .field("user", "kimchy")
                        .field("postDate", new Date())
                        .field("message", "another post")
                    .endObject()
                  )
        );

BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
    // process failures by iterating through each bulk response item
    //处理失败
}

使用 Bulk Processor

BulkProcessor 提供了一个简单的接口,在给定的大小数量上定时批量自动请求

创建BulkProcessor实例

首先创建BulkProcessor实例

import org.elasticsearch.action.bulk.BackoffPolicy;
import org.elasticsearch.action.bulk.BulkProcessor;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
BulkProcessor bulkProcessor = BulkProcessor.builder(
        client,  //增加elasticsearch客户端
        new BulkProcessor.Listener() {
            @Override
            public void beforeBulk(long executionId,
                                   BulkRequest request) { ... } //调用bulk之前执行 ,例如你可以通过request.numberOfActions()方法知道numberOfActions

            @Override
            public void afterBulk(long executionId,
                                  BulkRequest request,
                                  BulkResponse response) { ... } //调用bulk之后执行 ,例如你可以通过request.hasFailures()方法知道是否执行失败

            @Override
            public void afterBulk(long executionId,
                                  BulkRequest request,
                                  Throwable failure) { ... } //调用失败抛 Throwable
        })
        .setBulkActions(10000) //每次10000请求
        .setBulkSize(new ByteSizeValue(5, ByteSizeUnit.MB)) //拆成5mb一块
        .setFlushInterval(TimeValue.timeValueSeconds(5)) //无论请求数量多少,每5秒钟请求一次。
        .setConcurrentRequests(1) //设置并发请求的数量。值为0意味着只允许执行一个请求。值为1意味着允许1并发请求。
        .setBackoffPolicy(
            BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(100), 3))//设置自定义重复请求机制,最开始等待100毫秒,之后成倍更加,重试3次,当一次或多次重复请求失败后因为计算资源不够抛出 EsRejectedExecutionException 异常,可以通过BackoffPolicy.noBackoff()方法关闭重试机制
        .build();

BulkProcessor 默认设置

  • bulkActions  1000 
  • bulkSize 5mb
  • 不设置flushInterval
  • concurrentRequests 为 1 ,异步执行
  • backoffPolicy 重试 8次,等待50毫秒

增加requests

然后增加requestsBulkProcessor

bulkProcessor.add(new IndexRequest("twitter", "tweet", "1").source(/* your doc here */));
bulkProcessor.add(new DeleteRequest("twitter", "tweet", "2"));

关闭 Bulk Processor

当所有文档都处理完成,使用awaitCloseclose 方法关闭BulkProcessor:

bulkProcessor.awaitClose(10, TimeUnit.MINUTES);

bulkProcessor.close();

在测试中使用Bulk Processor

如果你在测试种使用Bulk Processor可以执行同步方法

BulkProcessor bulkProcessor = BulkProcessor.builder(client, new BulkProcessor.Listener() { /* Listener methods */ })
        .setBulkActions(10000)
        .setConcurrentRequests(0)
        .build();

// Add your requests
bulkProcessor.add(/* Your requests */);

// Flush any remaining requests
bulkProcessor.flush();

// Or close the bulkProcessor if you don't need it anymore
bulkProcessor.close();

// Refresh your indices
client.admin().indices().prepareRefresh().get();

// Now you can start searching!
client.prepareSearch().get();

所有实例 已经上传到Git

更多请浏览 spring-boot-starter-es 开源项目

如何有任何问题请关注微信公众号给我留言

qrcode_for_gh_26893aa0a4ea_258.jpg

 

继续阅读 »

本节介绍以下 CRUD API:

 单文档  APIs

多文档 APIs

Multi Get API Bulk API

注意:所有的单文档的CRUD API,index参数只能接受单一的索引库名称,或者是一个指向单一索引库的alias。

Index API

Index API 允许我们存储一个JSON格式的文档,使数据可以被搜索。文档通过index、type、id唯一确定。我们可以自己提供一个id,或者也使用Index API 为我们自动生成一个。

这里有几种不同的方式来产生JSON格式的文档(document):

  • 手动方式,使用原生的byte[]或者String
  • 使用Map方式,会自动转换成与之等价的JSON
  • 使用第三方库来序列化beans,如Jackson
  • 使用内置的帮助类 XContentFactory.jsonBuilder()

手动方式

数据格式

String json = "{" +
        "\"user\":\"kimchy\"," +
        "\"postDate\":\"2013-01-30\"," +
        "\"message\":\"trying out Elasticsearch\"" +
    "}";
实例
/**  
 * 手动生成JSON  
 */  
@Test  
public void CreateJSON(){  
      
    String json = "{" +  
            "\"user\":\"fendo\"," +  
            "\"postDate\":\"2013-01-30\"," +  
            "\"message\":\"Hell word\"" +  
        "}";  
      
    IndexResponse response = client.prepareIndex("fendo", "fendodate")  
            .setSource(json)  
            .get();  
    System.out.println(response.getResult());  
      
}  

  Map方式

Map是key:value数据类型,可以代表json结构.

Map<String, Object> json = new HashMap<String, Object>();
json.put("user","kimchy");
json.put("postDate",new Date());
json.put("message","trying out Elasticsearch");
实例
 /**  
 * 使用集合  
 */  
@Test  
public void CreateList(){  
      
    Map<String, Object> json = new HashMap<String, Object>();  
    json.put("user","kimchy");  
    json.put("postDate","2013-01-30");  
    json.put("message","trying out Elasticsearch");  
      
    IndexResponse response = client.prepareIndex("fendo", "fendodate")  
            .setSource(json)  
            .get();  
    System.out.println(response.getResult());  
      
}  

  序列化方式

ElasticSearch已经使用了jackson,可以直接使用它把javabean转为json.

import com.fasterxml.jackson.databind.*;

// instance a json mapper
ObjectMapper mapper = new ObjectMapper(); // create once, reuse

// generate json
byte[] json = mapper.writeValueAsBytes(yourbeaninstance);
实例
/**  
 * 使用JACKSON序列化  
 * @throws Exception  
 */  
@Test  
public void CreateJACKSON() throws Exception{  
      
    CsdnBlog csdn=new CsdnBlog();  
    csdn.setAuthor("fendo");  
    csdn.setContent("这是JAVA书籍");  
    csdn.setTag("C");  
    csdn.setView("100");  
    csdn.setTitile("编程");  
    csdn.setDate(new Date().toString());  
      
    // instance a json mapper  
    ObjectMapper mapper = new ObjectMapper(); // create once, reuse  

    // generate json  
    byte[] json = mapper.writeValueAsBytes(csdn);  
      
    IndexResponse response = client.prepareIndex("fendo", "fendodate")  
            .setSource(json)  
            .get();  
    System.out.println(response.getResult());  
}  

  XContentBuilder帮助类方式

ElasticSearch提供了一个内置的帮助类XContentBuilder来产生JSON文档

// Index name
String _index = response.getIndex();
// Type name
String _type = response.getType();
// Document ID (generated or not)
String _id = response.getId();
// Version (if it's the first time you index this document, you will get: 1)
long _version = response.getVersion();
// status has stored current instance statement.
RestStatus status = response.status();
实例
/**  
 * 使用ElasticSearch 帮助类  
 * @throws IOException   
 */  
@Test  
public void CreateXContentBuilder() throws IOException{  
      
    XContentBuilder builder = XContentFactory.jsonBuilder()  
            .startObject()  
                .field("user", "ccse")  
                .field("postDate", new Date())  
                .field("message", "this is Elasticsearch")  
            .endObject();  
      
    IndexResponse response = client.prepareIndex("fendo", "fendodata").setSource(builder).get();  
    System.out.println("创建成功!");  
      
      
}  

综合实例

 
import java.io.IOException;  
import java.net.InetAddress;  
import java.net.UnknownHostException;  
import java.util.Date;  
import java.util.HashMap;  
import java.util.Map;  
  
import org.elasticsearch.action.index.IndexResponse;  
import org.elasticsearch.client.transport.TransportClient;  
import org.elasticsearch.common.settings.Settings;  
import org.elasticsearch.common.transport.InetSocketTransportAddress;  
import org.elasticsearch.common.xcontent.XContentBuilder;  
import org.elasticsearch.common.xcontent.XContentFactory;  
import org.elasticsearch.transport.client.PreBuiltTransportClient;  
import org.junit.Before;  
import org.junit.Test;  
  
import com.fasterxml.jackson.core.JsonProcessingException;  
import com.fasterxml.jackson.databind.ObjectMapper;  
  
public class CreateIndex {  
  
    private TransportClient client;  
      
    @Before  
    public void getClient() throws Exception{  
        //设置集群名称  
        Settings settings = Settings.builder().put("cluster.name", "my-application").build();// 集群名  
        //创建client  
        client  = new PreBuiltTransportClient(settings)  
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("127.0.0.1"), 9300));  
    }  
      
    /**  
     * 手动生成JSON  
     */  
    @Test  
    public void CreateJSON(){  
          
        String json = "{" +  
                "\"user\":\"fendo\"," +  
                "\"postDate\":\"2013-01-30\"," +  
                "\"message\":\"Hell word\"" +  
            "}";  
          
        IndexResponse response = client.prepareIndex("fendo", "fendodate")  
                .setSource(json)  
                .get();  
        System.out.println(response.getResult());  
          
    }  
      
      
    /**  
     * 使用集合  
     */  
    @Test  
    public void CreateList(){  
          
        Map<String, Object> json = new HashMap<String, Object>();  
        json.put("user","kimchy");  
        json.put("postDate","2013-01-30");  
        json.put("message","trying out Elasticsearch");  
          
        IndexResponse response = client.prepareIndex("fendo", "fendodate")  
                .setSource(json)  
                .get();  
        System.out.println(response.getResult());  
          
    }  
      
    /**  
     * 使用JACKSON序列化  
     * @throws Exception  
     */  
    @Test  
    public void CreateJACKSON() throws Exception{  
          
        CsdnBlog csdn=new CsdnBlog();  
        csdn.setAuthor("fendo");  
        csdn.setContent("这是JAVA书籍");  
        csdn.setTag("C");  
        csdn.setView("100");  
        csdn.setTitile("编程");  
        csdn.setDate(new Date().toString());  
          
        // instance a json mapper  
        ObjectMapper mapper = new ObjectMapper(); // create once, reuse  
  
        // generate json  
        byte[] json = mapper.writeValueAsBytes(csdn);  
          
        IndexResponse response = client.prepareIndex("fendo", "fendodate")  
                .setSource(json)  
                .get();  
        System.out.println(response.getResult());  
    }  
      
    /**  
     * 使用ElasticSearch 帮助类  
     * @throws IOException   
     */  
    @Test  
    public void CreateXContentBuilder() throws IOException{  
          
        XContentBuilder builder = XContentFactory.jsonBuilder()  
                .startObject()  
                    .field("user", "ccse")  
                    .field("postDate", new Date())  
                    .field("message", "this is Elasticsearch")  
                .endObject();  
          
        IndexResponse response = client.prepareIndex("fendo", "fendodata").setSource(builder).get();  
        System.out.println("创建成功!");  
          
          
    }  
      
}  

你还可以通过startArray(string)和endArray()方法添加数组。.field()方法可以接受多种对象类型。你可以给它传递数字、日期、甚至其他XContentBuilder对象。

Get API

根据id查看文档:

GetResponse response = client.prepareGet("twitter", "tweet", "1").get();

更多请查看 rest get API 文档

配置线程

operationThreaded 设置为 true 是在不同的线程里执行此次操作

下面的例子是operationThreaded 设置为 false

GetResponse response = client.prepareGet("twitter", "tweet", "1")
        .setOperationThreaded(false)
        .get();

Delete API

根据ID删除:

DeleteResponse response = client.prepareDelete("twitter", "tweet", "1").get();

更多请查看 delete API 文档

配置线程

operationThreaded 设置为 true 是在不同的线程里执行此次操作

下面的例子是operationThreaded 设置为 false

GetResponse response = client.prepareGet("twitter", "tweet", "1")
        .setOperationThreaded(false)
        .get();
DeleteResponse response = client.prepareDelete("twitter", "tweet", "1")
        .setOperationThreaded(false)
        .get();

Delete By Query API

通过查询条件删除

BulkByScrollResponse response =
    DeleteByQueryAction.INSTANCE.newRequestBuilder(client)
        .filter(QueryBuilders.matchQuery("gender", "male")) //查询条件
        .source("persons") //index(索引名)
        .get();  //执行

long deleted = response.getDeleted(); //删除文档的数量

如果需要执行的时间比较长,可以使用异步的方式处理,结果在回调里面获取

DeleteByQueryAction.INSTANCE.newRequestBuilder(client)
    .filter(QueryBuilders.matchQuery("gender", "male"))      //查询            
    .source("persons")                //index(索引名)                                    
    .execute(new ActionListener<BulkByScrollResponse>() {     //回调监听     
        @Override
        public void onResponse(BulkByScrollResponse response) {
            long deleted = response.getDeleted();   //删除文档的数量                 
        }
        @Override
        public void onFailure(Exception e) {
            // Handle the exception
        }
    });

Update API

有两种方式更新索引:

  • 创建 UpdateRequest,通过client发送;
  • 使用 prepareUpdate() 方法;

使用UpdateRequest

UpdateRequest updateRequest = new UpdateRequest();
updateRequest.index("index");
updateRequest.type("type");
updateRequest.id("1");
updateRequest.doc(jsonBuilder()
        .startObject()
            .field("gender", "male")
        .endObject());
client.update(updateRequest).get();

使用 prepareUpdate() 方法

这里官方的示例有问题,new Script()参数错误,所以一下代码是我自己写的(2017/11/10)

client.prepareUpdate("ttl", "doc", "1")
        .setScript(new Script("ctx._source.gender = \"male\""  ,ScriptService.ScriptType.INLINE, null, null))//脚本可以是本地文件存储的,如果使用文件存储的脚本,需要设置 ScriptService.ScriptType.FILE 
        .get();

client.prepareUpdate("ttl", "doc", "1")
        .setDoc(jsonBuilder()   //合并到现有文档
            .startObject()
                .field("gender", "male")
            .endObject())
        .get();

Update by script

使用脚本更新文档 

UpdateRequest updateRequest = new UpdateRequest("ttl", "doc", "1")
        .script(new Script("ctx._source.gender = \"male\""));
client.update(updateRequest).get();

Update by merging documents

合并文档

UpdateRequest updateRequest = new UpdateRequest("index", "type", "1")
        .doc(jsonBuilder()
            .startObject()
                .field("gender", "male")
            .endObject());
client.update(updateRequest).get();

Upsert

更新插入,如果存在文档就更新,如果不存在就插入

IndexRequest indexRequest = new IndexRequest("index", "type", "1")
        .source(jsonBuilder()
            .startObject()
                .field("name", "Joe Smith")
                .field("gender", "male")
            .endObject());
UpdateRequest updateRequest = new UpdateRequest("index", "type", "1")
        .doc(jsonBuilder()
            .startObject()
                .field("gender", "male")
            .endObject())
        .upsert(indexRequest); //如果不存在此文档 ,就增加 `indexRequest`
client.update(updateRequest).get();

如果 index/type/1 存在,类似下面的文档:

{
    "name"  : "Joe Dalton",
    "gender": "male"        
}

如果不存在,会插入新的文档:

{
    "name" : "Joe Smith",
    "gender": "male"
}

Multi Get API

一次获取多个文档

MultiGetResponse multiGetItemResponses = client.prepareMultiGet()
    .add("twitter", "tweet", "1") //一个id的方式
    .add("twitter", "tweet", "2", "3", "4") //多个id的方式
    .add("another", "type", "foo")  //可以从另外一个索引获取
    .get();

for (MultiGetItemResponse itemResponse : multiGetItemResponses) { //迭代返回值
    GetResponse response = itemResponse.getResponse();
    if (response.isExists()) {      //判断是否存在                
        String json = response.getSourceAsString(); //_source 字段
    }
}

更多请浏览REST multi get 文档

Bulk API

Bulk API,批量插入:

import static org.elasticsearch.common.xcontent.XContentFactory.*;
BulkRequestBuilder bulkRequest = client.prepareBulk();

// either use client#prepare, or use Requests# to directly build index/delete requests
bulkRequest.add(client.prepareIndex("twitter", "tweet", "1")
        .setSource(jsonBuilder()
                    .startObject()
                        .field("user", "kimchy")
                        .field("postDate", new Date())
                        .field("message", "trying out Elasticsearch")
                    .endObject()
                  )
        );

bulkRequest.add(client.prepareIndex("twitter", "tweet", "2")
        .setSource(jsonBuilder()
                    .startObject()
                        .field("user", "kimchy")
                        .field("postDate", new Date())
                        .field("message", "another post")
                    .endObject()
                  )
        );

BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
    // process failures by iterating through each bulk response item
    //处理失败
}

使用 Bulk Processor

BulkProcessor 提供了一个简单的接口,在给定的大小数量上定时批量自动请求

创建BulkProcessor实例

首先创建BulkProcessor实例

import org.elasticsearch.action.bulk.BackoffPolicy;
import org.elasticsearch.action.bulk.BulkProcessor;
import org.elasticsearch.common.unit.ByteSizeUnit;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
BulkProcessor bulkProcessor = BulkProcessor.builder(
        client,  //增加elasticsearch客户端
        new BulkProcessor.Listener() {
            @Override
            public void beforeBulk(long executionId,
                                   BulkRequest request) { ... } //调用bulk之前执行 ,例如你可以通过request.numberOfActions()方法知道numberOfActions

            @Override
            public void afterBulk(long executionId,
                                  BulkRequest request,
                                  BulkResponse response) { ... } //调用bulk之后执行 ,例如你可以通过request.hasFailures()方法知道是否执行失败

            @Override
            public void afterBulk(long executionId,
                                  BulkRequest request,
                                  Throwable failure) { ... } //调用失败抛 Throwable
        })
        .setBulkActions(10000) //每次10000请求
        .setBulkSize(new ByteSizeValue(5, ByteSizeUnit.MB)) //拆成5mb一块
        .setFlushInterval(TimeValue.timeValueSeconds(5)) //无论请求数量多少,每5秒钟请求一次。
        .setConcurrentRequests(1) //设置并发请求的数量。值为0意味着只允许执行一个请求。值为1意味着允许1并发请求。
        .setBackoffPolicy(
            BackoffPolicy.exponentialBackoff(TimeValue.timeValueMillis(100), 3))//设置自定义重复请求机制,最开始等待100毫秒,之后成倍更加,重试3次,当一次或多次重复请求失败后因为计算资源不够抛出 EsRejectedExecutionException 异常,可以通过BackoffPolicy.noBackoff()方法关闭重试机制
        .build();

BulkProcessor 默认设置

  • bulkActions  1000 
  • bulkSize 5mb
  • 不设置flushInterval
  • concurrentRequests 为 1 ,异步执行
  • backoffPolicy 重试 8次,等待50毫秒

增加requests

然后增加requestsBulkProcessor

bulkProcessor.add(new IndexRequest("twitter", "tweet", "1").source(/* your doc here */));
bulkProcessor.add(new DeleteRequest("twitter", "tweet", "2"));

关闭 Bulk Processor

当所有文档都处理完成,使用awaitCloseclose 方法关闭BulkProcessor:

bulkProcessor.awaitClose(10, TimeUnit.MINUTES);

bulkProcessor.close();

在测试中使用Bulk Processor

如果你在测试种使用Bulk Processor可以执行同步方法

BulkProcessor bulkProcessor = BulkProcessor.builder(client, new BulkProcessor.Listener() { /* Listener methods */ })
        .setBulkActions(10000)
        .setConcurrentRequests(0)
        .build();

// Add your requests
bulkProcessor.add(/* Your requests */);

// Flush any remaining requests
bulkProcessor.flush();

// Or close the bulkProcessor if you don't need it anymore
bulkProcessor.close();

// Refresh your indices
client.admin().indices().prepareRefresh().get();

// Now you can start searching!
client.prepareSearch().get();

所有实例 已经上传到Git

更多请浏览 spring-boot-starter-es 开源项目

如何有任何问题请关注微信公众号给我留言

qrcode_for_gh_26893aa0a4ea_258.jpg

 

收起阅读 »

Elasticsearch Java API - 客户端连接(TransportClient,PreBuiltXPackTransportClient)(一)

Elasticsearch Java API 客户端连接

一个是TransportClient,一个是NodeClient,还有一个XPackTransportClient

  • TransportClient:

作为一个外部访问者,请求ES的集群,对于集群而言,它是一个外部因素。

  • NodeClient

作为ES集群的一个节点,它是ES中的一环,其他的节点对它是感知的。

  • XPackTransportClient:

服务安装了 x-pack 插件

重要:客户端版本应该和服务端版本保持一致

TransportClient旨在被Java高级REST客户端取代,该客户端执行HTTP请求而不是序列化的Java请求。 在即将到来的Elasticsearch版本中将不赞成使用TransportClient,建议使用Java高级REST客户端。

上面的警告比较尴尬,但是在 5xx版本中使用还是没有问题的,可能使用rest 客户端兼容性更好做一些。

Elasticsearch Java Rest API 手册

Maven Repository

Elasticsearch Java API包已经上传到 Maven Central

pom.xml文件中增加:

transport 版本号最好就是与Elasticsearch版本号一致。

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>5.6.3</version>
</dependency>

Transport Client

不设置集群名称

// on startup

//此步骤添加IP,至少一个,如果设置了"client.transport.sniff"= true 一个就够了,因为添加了自动嗅探配置
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));

// on shutdown  关闭client

client.close();

设置集群名称

Settings settings = Settings.builder()
        .put("cluster.name", "myClusterName").build();  //设置ES实例的名称
TransportClient client = new PreBuiltTransportClient(settings);  //自动嗅探整个集群的状态,把集群中其他ES节点的ip添加到本地的客户端列表中
//Add transport addresses and do something with the client...

增加自动嗅探配置

Settings settings = Settings.builder()
        .put("client.transport.sniff", true).build();
TransportClient client = new PreBuiltTransportClient(settings);

其他配置

client.transport.ignore_cluster_name  //设置 true ,忽略连接节点集群名验证
client.transport.ping_timeout       //ping一个节点的响应时间 默认5秒
client.transport.nodes_sampler_interval //sample/ping 节点的时间间隔,默认是5s

对于ES Client,有两种形式,一个是TransportClient,一个是NodeClient。两个的区别为: TransportClient作为一个外部访问者,通过HTTP去请求ES的集群,对于集群而言,它是一个外部因素。 NodeClient顾名思义,是作为ES集群的一个节点,它是ES中的一环,其他的节点对它是感知的,不像TransportClient那样,ES集群对它一无所知。NodeClient通信的性能会更好,但是因为是ES的一环,所以它出问题,也会给ES集群带来问题。NodeClient可以设置不作为数据节点,在elasticsearch.yml中设置,这样就不会在此节点上分配数据。

如果用ES的节点,仁者见仁智者见智。

实例

package name.quanke.es.study;

import name.quanke.es.study.util.Utils;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.After;
import org.junit.Before;

import java.net.InetAddress;

/**
 * Elasticsearch 5.5.1 的client 和 ElasticsearchTemplate的初始化
 * 作为一个外部访问者,请求ES的集群,对于集群而言,它是一个外部因素。
 * Created by http://quanke.name on 2017/11/10.
 */
public class ElasticsearchClient {

    protected TransportClient client;

    @Before
    public void setUp() throws Exception {

        Settings esSettings = Settings.builder()
                .put("cluster.name", "utan-es") //设置ES实例的名称
                .put("client.transport.sniff", true) //自动嗅探整个集群的状态,把集群中其他ES节点的ip添加到本地的客户端列表中
                .build();

        /**
         * 这里的连接方式指的是没有安装x-pack插件,如果安装了x-pack则参考{@link ElasticsearchXPackClient}
         * 1. java客户端的方式是以tcp协议在9300端口上进行通信
         * 2. http客户端的方式是以http协议在9200端口上进行通信
         */
        client = new PreBuiltTransportClient(esSettings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.1.10"), 9300));

        System.out.println("ElasticsearchClient 连接成功");
    }

    @After
    public void tearDown() throws Exception {
        if (client != null) {
            client.close();
        }

    }

    protected void println(SearchResponse searchResponse) {
        Utils.println(searchResponse);
    }

}

本实例代码已经上传到 Git ElasticsearchClient.java

所有实例 已经上传到Git

XPackTransportClient

如果 ElasticSearch 服务安装了 x-pack 插件,需要PreBuiltXPackTransportClient实例才能访问

使用Maven管理项目,把下面代码增加到pom.xml;

一定要修改默认仓库地址为https://artifacts.elastic.co/maven ,因为这个库没有上传到Maven中央仓库,如果有自己的 maven ,请配置代理

<project ...>

   <repositories>
      <!-- add the elasticsearch repo -->
      <repository>
         <id>elasticsearch-releases</id>
         <url>https://artifacts.elastic.co/maven</url>
         <releases>
            <enabled>true</enabled>
         </releases>
         <snapshots>
            <enabled>false</enabled>
         </snapshots>
      </repository>
      ...
   </repositories>
   ...

   <dependencies>
      <!-- add the x-pack jar as a dependency -->
      <dependency>
         <groupId>org.elasticsearch.client</groupId>
         <artifactId>x-pack-transport</artifactId>
         <version>5.6.3</version>
      </dependency>
      ...
   </dependencies>
   ...

 </project>

实例


/**
 * Elasticsearch XPack Client
 * Created by http://quanke.name on 2017/11/10.
 */
public class ElasticsearchXPackClient {

    protected TransportClient client;

    @Before
    public void setUp() throws Exception {
        /**
         * 如果es集群安装了x-pack插件则以此种方式连接集群
         * 1. java客户端的方式是以tcp协议在9300端口上进行通信
         * 2. http客户端的方式是以http协议在9200端口上进行通信
         */
        Settings settings = Settings.builder()
                .put("xpack.security.user", "elastic:utan100")
                .put("cluster.name", "utan-es")
                .build();
        client = new PreBuiltXPackTransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.1.10"), 9300));
//        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
//        credentialsProvider.setCredentials(AuthScope.ANY,
//                new UsernamePasswordCredentials("elastic", "utan100"));

        System.out.println("ElasticsearchXPackClient 启动成功");
    }

    @Test
    public void testClientConnection() throws Exception {

        System.out.println("--------------------------");
    }

    @After
    public void tearDown() throws Exception {
        if (client != null) {
            client.close();
        }

    }

    protected void println(SearchResponse searchResponse) {
        Utils.println(searchResponse);
    }
}

本实例代码已经上传到 Git ElasticsearchXPackClient.java

所有实例 已经上传到Git

更多请浏览 spring-boot-starter-es 开源项目

如何有任何问题请关注微信公众号给我留言

qrcode_for_gh_26893aa0a4ea_258.jpg

继续阅读 »

Elasticsearch Java API 客户端连接

一个是TransportClient,一个是NodeClient,还有一个XPackTransportClient

  • TransportClient:

作为一个外部访问者,请求ES的集群,对于集群而言,它是一个外部因素。

  • NodeClient

作为ES集群的一个节点,它是ES中的一环,其他的节点对它是感知的。

  • XPackTransportClient:

服务安装了 x-pack 插件

重要:客户端版本应该和服务端版本保持一致

TransportClient旨在被Java高级REST客户端取代,该客户端执行HTTP请求而不是序列化的Java请求。 在即将到来的Elasticsearch版本中将不赞成使用TransportClient,建议使用Java高级REST客户端。

上面的警告比较尴尬,但是在 5xx版本中使用还是没有问题的,可能使用rest 客户端兼容性更好做一些。

Elasticsearch Java Rest API 手册

Maven Repository

Elasticsearch Java API包已经上传到 Maven Central

pom.xml文件中增加:

transport 版本号最好就是与Elasticsearch版本号一致。

<dependency>
    <groupId>org.elasticsearch.client</groupId>
    <artifactId>transport</artifactId>
    <version>5.6.3</version>
</dependency>

Transport Client

不设置集群名称

// on startup

//此步骤添加IP,至少一个,如果设置了"client.transport.sniff"= true 一个就够了,因为添加了自动嗅探配置
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host1"), 9300))
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("host2"), 9300));

// on shutdown  关闭client

client.close();

设置集群名称

Settings settings = Settings.builder()
        .put("cluster.name", "myClusterName").build();  //设置ES实例的名称
TransportClient client = new PreBuiltTransportClient(settings);  //自动嗅探整个集群的状态,把集群中其他ES节点的ip添加到本地的客户端列表中
//Add transport addresses and do something with the client...

增加自动嗅探配置

Settings settings = Settings.builder()
        .put("client.transport.sniff", true).build();
TransportClient client = new PreBuiltTransportClient(settings);

其他配置

client.transport.ignore_cluster_name  //设置 true ,忽略连接节点集群名验证
client.transport.ping_timeout       //ping一个节点的响应时间 默认5秒
client.transport.nodes_sampler_interval //sample/ping 节点的时间间隔,默认是5s

对于ES Client,有两种形式,一个是TransportClient,一个是NodeClient。两个的区别为: TransportClient作为一个外部访问者,通过HTTP去请求ES的集群,对于集群而言,它是一个外部因素。 NodeClient顾名思义,是作为ES集群的一个节点,它是ES中的一环,其他的节点对它是感知的,不像TransportClient那样,ES集群对它一无所知。NodeClient通信的性能会更好,但是因为是ES的一环,所以它出问题,也会给ES集群带来问题。NodeClient可以设置不作为数据节点,在elasticsearch.yml中设置,这样就不会在此节点上分配数据。

如果用ES的节点,仁者见仁智者见智。

实例

package name.quanke.es.study;

import name.quanke.es.study.util.Utils;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import org.junit.After;
import org.junit.Before;

import java.net.InetAddress;

/**
 * Elasticsearch 5.5.1 的client 和 ElasticsearchTemplate的初始化
 * 作为一个外部访问者,请求ES的集群,对于集群而言,它是一个外部因素。
 * Created by http://quanke.name on 2017/11/10.
 */
public class ElasticsearchClient {

    protected TransportClient client;

    @Before
    public void setUp() throws Exception {

        Settings esSettings = Settings.builder()
                .put("cluster.name", "utan-es") //设置ES实例的名称
                .put("client.transport.sniff", true) //自动嗅探整个集群的状态,把集群中其他ES节点的ip添加到本地的客户端列表中
                .build();

        /**
         * 这里的连接方式指的是没有安装x-pack插件,如果安装了x-pack则参考{@link ElasticsearchXPackClient}
         * 1. java客户端的方式是以tcp协议在9300端口上进行通信
         * 2. http客户端的方式是以http协议在9200端口上进行通信
         */
        client = new PreBuiltTransportClient(esSettings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.1.10"), 9300));

        System.out.println("ElasticsearchClient 连接成功");
    }

    @After
    public void tearDown() throws Exception {
        if (client != null) {
            client.close();
        }

    }

    protected void println(SearchResponse searchResponse) {
        Utils.println(searchResponse);
    }

}

本实例代码已经上传到 Git ElasticsearchClient.java

所有实例 已经上传到Git

XPackTransportClient

如果 ElasticSearch 服务安装了 x-pack 插件,需要PreBuiltXPackTransportClient实例才能访问

使用Maven管理项目,把下面代码增加到pom.xml;

一定要修改默认仓库地址为https://artifacts.elastic.co/maven ,因为这个库没有上传到Maven中央仓库,如果有自己的 maven ,请配置代理

<project ...>

   <repositories>
      <!-- add the elasticsearch repo -->
      <repository>
         <id>elasticsearch-releases</id>
         <url>https://artifacts.elastic.co/maven</url>
         <releases>
            <enabled>true</enabled>
         </releases>
         <snapshots>
            <enabled>false</enabled>
         </snapshots>
      </repository>
      ...
   </repositories>
   ...

   <dependencies>
      <!-- add the x-pack jar as a dependency -->
      <dependency>
         <groupId>org.elasticsearch.client</groupId>
         <artifactId>x-pack-transport</artifactId>
         <version>5.6.3</version>
      </dependency>
      ...
   </dependencies>
   ...

 </project>

实例


/**
 * Elasticsearch XPack Client
 * Created by http://quanke.name on 2017/11/10.
 */
public class ElasticsearchXPackClient {

    protected TransportClient client;

    @Before
    public void setUp() throws Exception {
        /**
         * 如果es集群安装了x-pack插件则以此种方式连接集群
         * 1. java客户端的方式是以tcp协议在9300端口上进行通信
         * 2. http客户端的方式是以http协议在9200端口上进行通信
         */
        Settings settings = Settings.builder()
                .put("xpack.security.user", "elastic:utan100")
                .put("cluster.name", "utan-es")
                .build();
        client = new PreBuiltXPackTransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("192.168.1.10"), 9300));
//        final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
//        credentialsProvider.setCredentials(AuthScope.ANY,
//                new UsernamePasswordCredentials("elastic", "utan100"));

        System.out.println("ElasticsearchXPackClient 启动成功");
    }

    @Test
    public void testClientConnection() throws Exception {

        System.out.println("--------------------------");
    }

    @After
    public void tearDown() throws Exception {
        if (client != null) {
            client.close();
        }

    }

    protected void println(SearchResponse searchResponse) {
        Utils.println(searchResponse);
    }
}

本实例代码已经上传到 Git ElasticsearchXPackClient.java

所有实例 已经上传到Git

更多请浏览 spring-boot-starter-es 开源项目

如何有任何问题请关注微信公众号给我留言

qrcode_for_gh_26893aa0a4ea_258.jpg

收起阅读 »

Elastic Stack 全新推出 6.0.0

1510725544562.jpg

https://www.elastic.co/cn/blog/elastic-stack-6-0-0-released

全新推出 6.0.0。

无需多说。你应该立即下载试用,或者通过你最喜欢的托管式 Elasticsearch 和 Kibana 提供平台 Elastic Cloud 亲身体验。

如果你在过去几个月没有跟上我们的发布节奏,可能会对今天的公告感到意外。今天标志着成千上万的 pull 请求和成百上千位代码提交者的努力终见成效。期间共有两个 alpha 版本、两个 beta 版本、两个候选版本以及最终的通用版本 (GA)。这个里程碑离不开 Elastic 各路团队的努力。还要感谢参与先锋计划的用户提出的意见和反馈。

今天,我们不仅发布了整套 Elastic Stack,还发布了 Elastic Cloud Enterprise 1.1,其中包括 6.0 支持、离线安装,并且对用户体验进行了一系列改进,旨在简化集群的配置、管理和监控。同天发布多款产品的正式版本还不够……还有仍是 Alpha 版本的 APM ,我们邀请大家在 6.0.0 中对它进行测试。

一个版本有如此多的亮点,该从哪里说起呢?你们撰文细述也好,提供详情链接也好,祝你们有愉快的阅读体验……更重要的是……祝你们有愉快的搜索、分析和可视化体验。

Elasticsearch

全新零停机升级体验,增加了序列 ID、改进了对稀疏数据的处理、加快了查询速度、分布式执行 watch 等等。功能摘要请查看详情

Kibana

支持 “Dashboard Only” 模式,支持 “全屏” 模式,能够将保存的搜索结果导出到 .csv,X-Pack 黄金版及以上版本支持通过 UI 创建告警,X-Pack 基础版提供迁移助手,我们还通过调整对比度、支持快捷键来产品易用性,让用户使用起来更方便。数据交互的未来详见此贴

Logstash

单一 Logstash 实例中可存在多个自成体系的管道,另有新增 UI 组件 - X-Pack 基础版中的管道查看器,以及 X-Pack 黄金版中的 Logstash 管道管理。了解详情,点这里

Beats

Beats <3 容器以及 Beats <3 模块(并且改进了适用于这些模块的仪表板)。再结合全新命令和配置布局,在 Metricbeat 实现更高效的存储。此外,全新推出 Auditbeat。细节详见这里

ES-Hadoop

对Spark的结构化数据流的一流支持已经降落到了 6.0,并重新编写了连接器映射代码以更好地支持多个映射。支持读写新的连接字段也被添加了。用户现在也可以利用非内联脚本类型的更新操作。详细信息

立即获取!

继续阅读 »

1510725544562.jpg

https://www.elastic.co/cn/blog/elastic-stack-6-0-0-released

全新推出 6.0.0。

无需多说。你应该立即下载试用,或者通过你最喜欢的托管式 Elasticsearch 和 Kibana 提供平台 Elastic Cloud 亲身体验。

如果你在过去几个月没有跟上我们的发布节奏,可能会对今天的公告感到意外。今天标志着成千上万的 pull 请求和成百上千位代码提交者的努力终见成效。期间共有两个 alpha 版本、两个 beta 版本、两个候选版本以及最终的通用版本 (GA)。这个里程碑离不开 Elastic 各路团队的努力。还要感谢参与先锋计划的用户提出的意见和反馈。

今天,我们不仅发布了整套 Elastic Stack,还发布了 Elastic Cloud Enterprise 1.1,其中包括 6.0 支持、离线安装,并且对用户体验进行了一系列改进,旨在简化集群的配置、管理和监控。同天发布多款产品的正式版本还不够……还有仍是 Alpha 版本的 APM ,我们邀请大家在 6.0.0 中对它进行测试。

一个版本有如此多的亮点,该从哪里说起呢?你们撰文细述也好,提供详情链接也好,祝你们有愉快的阅读体验……更重要的是……祝你们有愉快的搜索、分析和可视化体验。

Elasticsearch

全新零停机升级体验,增加了序列 ID、改进了对稀疏数据的处理、加快了查询速度、分布式执行 watch 等等。功能摘要请查看详情

Kibana

支持 “Dashboard Only” 模式,支持 “全屏” 模式,能够将保存的搜索结果导出到 .csv,X-Pack 黄金版及以上版本支持通过 UI 创建告警,X-Pack 基础版提供迁移助手,我们还通过调整对比度、支持快捷键来产品易用性,让用户使用起来更方便。数据交互的未来详见此贴

Logstash

单一 Logstash 实例中可存在多个自成体系的管道,另有新增 UI 组件 - X-Pack 基础版中的管道查看器,以及 X-Pack 黄金版中的 Logstash 管道管理。了解详情,点这里

Beats

Beats <3 容器以及 Beats <3 模块(并且改进了适用于这些模块的仪表板)。再结合全新命令和配置布局,在 Metricbeat 实现更高效的存储。此外,全新推出 Auditbeat。细节详见这里

ES-Hadoop

对Spark的结构化数据流的一流支持已经降落到了 6.0,并重新编写了连接器映射代码以更好地支持多个映射。支持读写新的连接字段也被添加了。用户现在也可以利用非内联脚本类型的更新操作。详细信息

立即获取!

收起阅读 »

上海普翔招聘 Elastic技术支持工程师

elastictech_logo.001_.png

 
 招聘职位:Elastic技术支持工程师

工作地点:上海

薪资待遇:18k ~ 25k

公司介绍:上海普翔是 elastic 目前在中国的合作伙伴,负责 X-Pack、ECE 产品销售以及技术咨询等 elastic相关的业务,详情可以查看 http://elastictech.cn

工作内容:

1、与 Elastic 公司一起挖掘国内的付费用户,拜访客户并介绍 X-Pack 、ECE 等产品。

2、参与国内付费用户的 elastic 产品实践,帮助他们解决实际中遇到的问题。

3、参与国内 elastic 产品的推广工作,比如录制教学视频、直播等。

职位要求:

1、本科以上学历,3年以上工作经验。

2、熟悉 Elastic 产品(如 Elasticsearch、Kibana、Logstash、Beats )的使用方法,了解常见优化方案,可以解决社区和客户中用户遇到的问题。

3、需要极强的学习和研究能力,面对一个新产品或者特性时,可以在极短的时间内掌握并通过自己的语言给客户讲解和演示。

4、有良好的沟通和表达能力,擅长倾听客户的问题并快速定位解决问题的关键点。

我们是 elastic 的官方合作伙伴,所以会有很多最新的信息与资料,对 elastic 在中国的发展有信心的同学不要错过机会哦!

欢迎投递简历至:weibinway@elastictech.cn


 
 
继续阅读 »
elastictech_logo.001_.png

 
 招聘职位:Elastic技术支持工程师

工作地点:上海

薪资待遇:18k ~ 25k

公司介绍:上海普翔是 elastic 目前在中国的合作伙伴,负责 X-Pack、ECE 产品销售以及技术咨询等 elastic相关的业务,详情可以查看 http://elastictech.cn

工作内容:

1、与 Elastic 公司一起挖掘国内的付费用户,拜访客户并介绍 X-Pack 、ECE 等产品。

2、参与国内付费用户的 elastic 产品实践,帮助他们解决实际中遇到的问题。

3、参与国内 elastic 产品的推广工作,比如录制教学视频、直播等。

职位要求:

1、本科以上学历,3年以上工作经验。

2、熟悉 Elastic 产品(如 Elasticsearch、Kibana、Logstash、Beats )的使用方法,了解常见优化方案,可以解决社区和客户中用户遇到的问题。

3、需要极强的学习和研究能力,面对一个新产品或者特性时,可以在极短的时间内掌握并通过自己的语言给客户讲解和演示。

4、有良好的沟通和表达能力,擅长倾听客户的问题并快速定位解决问题的关键点。

我们是 elastic 的官方合作伙伴,所以会有很多最新的信息与资料,对 elastic 在中国的发展有信心的同学不要错过机会哦!

欢迎投递简历至:weibinway@elastictech.cn


 
  收起阅读 »

社区日报 第101期 (2017-11-15)

1、Elastic stack 6.0正式亮相
https://www.elastic.co/blog/el ... eased
2、vts数据处理搜索引擎选型 
http://t.cn/RjfQx01 
3、如何监控、调优golang应用程序且看下文分晓 
http://t.cn/RlA4biz 
4、elasticsearch性能分析123 
http://t.cn/RjfEjN3 
5、只等你来 | Elastic Meetup 广州交流会 
https://elasticsearch.cn/article/364 
 
编辑:wt 
归档:https://elasticsearch.cn/article/377
订阅:https://tinyletter.com/elastic-daily
 
继续阅读 »
1、Elastic stack 6.0正式亮相
https://www.elastic.co/blog/el ... eased
2、vts数据处理搜索引擎选型 
http://t.cn/RjfQx01 
3、如何监控、调优golang应用程序且看下文分晓 
http://t.cn/RlA4biz 
4、elasticsearch性能分析123 
http://t.cn/RjfEjN3 
5、只等你来 | Elastic Meetup 广州交流会 
https://elasticsearch.cn/article/364 
 
编辑:wt 
归档:https://elasticsearch.cn/article/377
订阅:https://tinyletter.com/elastic-daily
  收起阅读 »

spark elasticsearch 异常: PowerSet: Too many elements to create a power set 40


org.elasticsearch.hadoop.EsHadoopIllegalArgumentException: Too many elements to create a power set 54
at org.elasticsearch.hadoop.util.Assert.isTrue(Assert.java:50)
at org.elasticsearch.hadoop.rest.ShardSorter$PowerSet.(ShardSorter.java:218)
at org.elasticsearch.hadoop.rest.ShardSorter.powerList(ShardSorter.java:202)
at org.elasticsearch.hadoop.rest.ShardSorter.checkCombo(ShardSorter.java:89)
at org.elasticsearch.hadoop.rest.ShardSorter.find(ShardSorter.java:85)
at org.elasticsearch.hadoop.rest.RestRepository.doGetReadTargetShards(RestRepository.java:352)
at org.elasticsearch.hadoop.rest.RestRepository.getReadTargetShards(RestRepository.java:295)
at org.elasticsearch.hadoop.rest.RestService.findPartitions(RestService.java:253)
at org.elasticsearch.spark.rdd.AbstractEsRDD.esPartitions$lzycompute(AbstractEsRDD.scala:61)
at org.elasticsearch.spark.rdd.AbstractEsRDD.esPartitions(AbstractEsRDD.scala:60)
at org.elasticsearch.spark.rdd.AbstractEsRDD.getPartitions(AbstractEsRDD.scala:27)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:239)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:237)
at scala.Option.getOrElse(Option.scala:120)
at org.apache.spark.rdd.RDD.partitions(RDD.scala:237)
at org.apache.spark.rdd.MapPartitionsRDD.getPartitions(MapPartitionsRDD.scala:35)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:239)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:237)Users with the same issue
 
解释:
Read failure when index/alias spread among 32 or more nodes
 
https://github.com/elastic/ela ... s/737
继续阅读 »

org.elasticsearch.hadoop.EsHadoopIllegalArgumentException: Too many elements to create a power set 54
at org.elasticsearch.hadoop.util.Assert.isTrue(Assert.java:50)
at org.elasticsearch.hadoop.rest.ShardSorter$PowerSet.(ShardSorter.java:218)
at org.elasticsearch.hadoop.rest.ShardSorter.powerList(ShardSorter.java:202)
at org.elasticsearch.hadoop.rest.ShardSorter.checkCombo(ShardSorter.java:89)
at org.elasticsearch.hadoop.rest.ShardSorter.find(ShardSorter.java:85)
at org.elasticsearch.hadoop.rest.RestRepository.doGetReadTargetShards(RestRepository.java:352)
at org.elasticsearch.hadoop.rest.RestRepository.getReadTargetShards(RestRepository.java:295)
at org.elasticsearch.hadoop.rest.RestService.findPartitions(RestService.java:253)
at org.elasticsearch.spark.rdd.AbstractEsRDD.esPartitions$lzycompute(AbstractEsRDD.scala:61)
at org.elasticsearch.spark.rdd.AbstractEsRDD.esPartitions(AbstractEsRDD.scala:60)
at org.elasticsearch.spark.rdd.AbstractEsRDD.getPartitions(AbstractEsRDD.scala:27)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:239)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:237)
at scala.Option.getOrElse(Option.scala:120)
at org.apache.spark.rdd.RDD.partitions(RDD.scala:237)
at org.apache.spark.rdd.MapPartitionsRDD.getPartitions(MapPartitionsRDD.scala:35)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:239)
at org.apache.spark.rdd.RDD$$anonfun$partitions$2.apply(RDD.scala:237)Users with the same issue
 
解释:
Read failure when index/alias spread among 32 or more nodes
 
https://github.com/elastic/ela ... s/737 收起阅读 »

写在 社区 日报100期时 —— 相信社区的力量

community

我一直有看湾区日报的习惯,后来看到 Golang 中国社区的 astaxie 也在做 GoCN 每日新闻 的事情。日报对社区来讲是一件持续输出的事情,对个人来讲是一件持续输入的事情,于是我决定在 Elastic 社区也做这么一件事情,在2017年7月30日我发布了 Elastic日报 第1期

当天和 medcl 聊过后,他建议发动社区的力量来做,这样才能保证日报做好做久。于是我们开始在社区里面招募日报编辑,很快便有很多同学响应,接着 Elastic日报编辑部成立。到今天,我们一共有8位社区编辑,其中7位负责每周固定一天的日报,另一位负责审稿和公众号文章发布。他们分别是:

  • 江水
  • 金桥
  • bsll
  • 至尊宝
  • 叮咚光军
  • laoyang360
  • cyberdak
  • 陶文

感谢社区编辑们的付出,我们一同做了一件了不起的事情——持续100天的知识输出。如果有同学把这100天的日报内容都看完吃透,那它的Elastic 技术水准肯定提升了不止1个档次。

现在想来,如果是我一个人做这件事情,恐怕日报不会超过30期。个人的力量是有限的,而社区的力量是无限的。每天看到编辑们精挑细选的文章,我都会诧异 Elastic 相关的优秀文章可真是多啊!

相信社区的力量,让我们期待Elastic日报200期、300期甚至1000期的到来!

继续阅读 »

community

我一直有看湾区日报的习惯,后来看到 Golang 中国社区的 astaxie 也在做 GoCN 每日新闻 的事情。日报对社区来讲是一件持续输出的事情,对个人来讲是一件持续输入的事情,于是我决定在 Elastic 社区也做这么一件事情,在2017年7月30日我发布了 Elastic日报 第1期

当天和 medcl 聊过后,他建议发动社区的力量来做,这样才能保证日报做好做久。于是我们开始在社区里面招募日报编辑,很快便有很多同学响应,接着 Elastic日报编辑部成立。到今天,我们一共有8位社区编辑,其中7位负责每周固定一天的日报,另一位负责审稿和公众号文章发布。他们分别是:

  • 江水
  • 金桥
  • bsll
  • 至尊宝
  • 叮咚光军
  • laoyang360
  • cyberdak
  • 陶文

感谢社区编辑们的付出,我们一同做了一件了不起的事情——持续100天的知识输出。如果有同学把这100天的日报内容都看完吃透,那它的Elastic 技术水准肯定提升了不止1个档次。

现在想来,如果是我一个人做这件事情,恐怕日报不会超过30期。个人的力量是有限的,而社区的力量是无限的。每天看到编辑们精挑细选的文章,我都会诧异 Elastic 相关的优秀文章可真是多啊!

相信社区的力量,让我们期待Elastic日报200期、300期甚至1000期的到来!

收起阅读 »

社区日报 第100期 (2017-11-14)

1.使用Logstash将email索引至Elasticsearch。
http://t.cn/RjyNLge 
2.Elasticsearch选主流程详细分析。
http://t.cn/RjyNPLT 
3.手把手教你如何使用ES提高WordPress的搜索速度。
http://t.cn/RjbD1QK 
4.只等你来 | Elastic Meetup 广州交流会
https://elasticsearch.cn/article/364 


编辑:叮咚光军
归档:https://elasticsearch.cn/article/374 
订阅:https://tinyletter.com/elastic-daily
继续阅读 »
1.使用Logstash将email索引至Elasticsearch。
http://t.cn/RjyNLge 
2.Elasticsearch选主流程详细分析。
http://t.cn/RjyNPLT 
3.手把手教你如何使用ES提高WordPress的搜索速度。
http://t.cn/RjbD1QK 
4.只等你来 | Elastic Meetup 广州交流会
https://elasticsearch.cn/article/364 


编辑:叮咚光军
归档:https://elasticsearch.cn/article/374 
订阅:https://tinyletter.com/elastic-daily 收起阅读 »

从es2.3到5.6的迁移实践

config/elasticsearch.yml

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/e ... .html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
cluster.name: es5_dev
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
node.name: es5-node03
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: ["127.0.0.1","10.204.12.33"]
http.port: 9201
transport.tcp.port: 9301
#http.host: 127.0.0.1
#http.enabled: false
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
node.master: true
node.data: true
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts:
   - 10.204.12.31:9301
   - 10.204.12.32:9301
   - 10.204.12.33:9301
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
indices.requests.cache.size: 5%
config/jvm.options

## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/e ... .html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms2g
-Xmx2g
################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################
## GC configuration
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
## optimizations
# pre-touch memory pages used by the JVM during initialization
-XX:+AlwaysPreTouch
## basic
# force the server VM (remove on 32-bit client JVMs)
-server
# explicitly set the stack size (reduce to 320k on 32-bit client JVMs)
-Xss1m
# set to headless, just in case
-Djava.awt.headless=true
# ensure UTF-8 encoding by default (e.g. filenames)
-Dfile.encoding=UTF-8
# use our provided JNA always versus the system one
-Djna.nosys=true
# use old-style file permissions on JDK9
-Djdk.io.permissionsUseCanonicalPath=true
# flags to configure Netty
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0
# log4j 2
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true
-Dlog4j.skipJansi=true
## heap dumps
# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError
# specify an alternative path for heap dumps
# ensure the directory exists and has sufficient space
#-XX:HeapDumpPath=${heap.dump.path}
## GC logging
#-XX:+PrintGCDetails
#-XX:+PrintGCTimeStamps
#-XX:+PrintGCDateStamps
#-XX:+PrintClassHistogram
#-XX:+PrintTenuringDistribution
#-XX:+PrintGCApplicationStoppedTime
# log GC status to a file with time stamps
# ensure the directory exists
#-Xloggc:${loggc}
# By default, the GC log file will not rotate.
# By uncommenting the lines below, the GC log file
# will be rotated every 128MB at most 32 times.
#-XX:+UseGCLogFileRotation
#-XX:NumberOfGCLogFiles=32
#-XX:GCLogFileSize=128M
# Elasticsearch 5.0.0 will throw an exception on unquoted field names in JSON.
# If documents were already indexed with unquoted fields in a previous version
# of Elasticsearch, some operations may throw errors.
#
# WARNING: This option will be removed in Elasticsearch 6.0.0 and is provided
# only for migration purposes.
#-Delasticsearch.json.allow_unquoted_field_names=true



安装ik分词器


bin/elasticsearch-plugin install https://github.com/medcl/elast ... 1.zip




./bin/elasticsearch-plugin install https://github.com/medcl/elast ... 3.zip



配置ik远程扩展词典用于热词更新 elasticsearch-5.6.3/config/analysis-ik/IKAnalyzer.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd&quot;&gt;
<properties>
       <comment>IK Analyzer 扩展配置</comment>
       <!--用户可以在这里配置自己的扩展字典 -->
       <entry key="ext_dict"></entry>
        <!--用户可以在这里配置自己的扩展停止词字典-->
       <entry key="ext_stopwords"></entry>
       <!--用户可以在这里配置远程扩展字典 -->
       <entry key="remote_ext_dict">http://distribute.search.leju. ... gt%3B
       <!--用户可以在这里配置远程扩展停止词字典-->
       <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
安装拼音分词器

cd elasticsearch-5.5.1/plugins
wget https://github.com/medcl/elast ... 5.5.1
unzip v5.5.1




打包部署其他节点时,先清理data目录




集群监控可以利用head的chrome插件




数据迁移

迁移工具是自己写的elasticbak,目前更新了5.6.3驱动。github链接:https://github.com/jiashiwen/elasticbak

数据备份

java -jar elasticbak-2.3.3.jar \
--exp \
--cluster lejuesdev \
--host 10.204.12.31 \
--filesize 1000 \
--backupdir ./esbackupset \
--backupindexes "*" \
--threads 4
由于版本field的变化需要手工重建索引,这里举个例子,主要是2.x版本的string需要改为text。2.x版本我们通过index参数指定该字段是否被索引("index": "no")以及是否通过分词器分词("index": "not_analyzed")。在5.X版本里index只用来制定是否创建索引,如果需要整个字段不过分词器创建索引,需要通过keyword字段完成。  

 

curl -XPUT "http://10.204.12.31:9201/house_geo&quot; -H 'Content-Type: application/json' -d'
{
 "mappings": {
   "house": {
     "dynamic": "strict",
     "_all": {
       "enabled": false
     },
     "properties": {
       "_category": {
         "type": "keyword",
                 "store": true
       },
       "_content": {
         "type": "text",
         "store": true,
         "analyzer": "ik_max_word",
         "search_analyzer": "ik_smart"
       },
       "_deleted": {
         "type": "boolean",
         "store": true
       },
       "_doccreatetime": {
         "type": "date",
         "store": true,
         "format": "strict_date_optional_time||epoch_millis||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
       },
       "_docupdatetime": {
         "type": "date",
         "store": true,
         "format": "strict_date_optional_time||epoch_millis||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
       },
       "_flags": {
         "type": "text",
         "store": true,
         "analyzer": "whitespace"
       },
       "_hits": {
         "type": "text"
       },
       "_location": {
         "type": "geo_point"
       },
       "_multi": {
         "properties": {
           "_location": {
             "type": "geo_point"
           }
         }
       },
       "_origin": {
         "type": "object",
         "enabled": false
       },
       "_scope": {
         "type": "keyword",
         "store": true
       },
       "_tags": {
         "type": "text",
         "boost": 10,
         "store": true,
         "term_vector": "with_positions_offsets",
         "analyzer": "ik_max_word",
         "search_analyzer": "ik_smart"
       },
       "_title": {
         "type": "text",
         "store": true,
         "analyzer": "ik_max_word",
         "search_analyzer": "ik_smart"
       },
       "_uniqid": {
         "type": "keyword",
         "store": true
       },
       "_uniqsign": {
         "type": "keyword",
         "store": true
       },
       "_url": {
         "type": "text",
         "index": false,
         "store": true
       },
       "location": {
         "type": "geo_point"
       }
     }
   }
 },
 "settings": {
   "index": {
     "number_of_shards": "3",
     "requests": {
       "cache": {
         "enable": "true"
       }
     },
     "analysis": {
       "filter": {
         "my_synonym": {
           "type": "synonym",
           "synonyms_path": "analysis-ik/custom/synonym.dic"
         }
       },
       "analyzer": {
         "searchanalyzer": {
           "filter": "my_synonym",
           "type": "custom",
           "tokenizer": "ik_smart"
         },
         "indexanalyzer": {
           "filter": "my_synonym",
           "type": "custom",
           "tokenizer": "ik_max_word"
         }
       }
     },
     "number_of_replicas": "1"
   }
 }
}'
利用新版elasticbak导入索引数据


java -jar elasticbak-5.6.3.jar \
--imp \
--cluster es5_dev \
--host 10.204.12.31 \
--port 9301 \
--restoreindex house_geo \
--restoretype dataonly \
--backupset esbackupset/house_geo \
--threads 4
 
继续阅读 »
config/elasticsearch.yml

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/e ... .html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
cluster.name: es5_dev
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
node.name: es5-node03
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
network.host: ["127.0.0.1","10.204.12.33"]
http.port: 9201
transport.tcp.port: 9301
#http.host: 127.0.0.1
#http.enabled: false
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
node.master: true
node.data: true
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts:
   - 10.204.12.31:9301
   - 10.204.12.32:9301
   - 10.204.12.33:9301
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
indices.requests.cache.size: 5%
config/jvm.options

## JVM configuration
################################################################
## IMPORTANT: JVM heap size
################################################################
##
## You should always set the min and max JVM heap
## size to the same value. For example, to set
## the heap to 4 GB, set:
##
## -Xms4g
## -Xmx4g
##
## See https://www.elastic.co/guide/e ... .html
## for more information
##
################################################################
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms2g
-Xmx2g
################################################################
## Expert settings
################################################################
##
## All settings below this section are considered
## expert settings. Don't tamper with them unless
## you understand what you are doing
##
################################################################
## GC configuration
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
## optimizations
# pre-touch memory pages used by the JVM during initialization
-XX:+AlwaysPreTouch
## basic
# force the server VM (remove on 32-bit client JVMs)
-server
# explicitly set the stack size (reduce to 320k on 32-bit client JVMs)
-Xss1m
# set to headless, just in case
-Djava.awt.headless=true
# ensure UTF-8 encoding by default (e.g. filenames)
-Dfile.encoding=UTF-8
# use our provided JNA always versus the system one
-Djna.nosys=true
# use old-style file permissions on JDK9
-Djdk.io.permissionsUseCanonicalPath=true
# flags to configure Netty
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0
# log4j 2
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true
-Dlog4j.skipJansi=true
## heap dumps
# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError
# specify an alternative path for heap dumps
# ensure the directory exists and has sufficient space
#-XX:HeapDumpPath=${heap.dump.path}
## GC logging
#-XX:+PrintGCDetails
#-XX:+PrintGCTimeStamps
#-XX:+PrintGCDateStamps
#-XX:+PrintClassHistogram
#-XX:+PrintTenuringDistribution
#-XX:+PrintGCApplicationStoppedTime
# log GC status to a file with time stamps
# ensure the directory exists
#-Xloggc:${loggc}
# By default, the GC log file will not rotate.
# By uncommenting the lines below, the GC log file
# will be rotated every 128MB at most 32 times.
#-XX:+UseGCLogFileRotation
#-XX:NumberOfGCLogFiles=32
#-XX:GCLogFileSize=128M
# Elasticsearch 5.0.0 will throw an exception on unquoted field names in JSON.
# If documents were already indexed with unquoted fields in a previous version
# of Elasticsearch, some operations may throw errors.
#
# WARNING: This option will be removed in Elasticsearch 6.0.0 and is provided
# only for migration purposes.
#-Delasticsearch.json.allow_unquoted_field_names=true



安装ik分词器


bin/elasticsearch-plugin install https://github.com/medcl/elast ... 1.zip




./bin/elasticsearch-plugin install https://github.com/medcl/elast ... 3.zip



配置ik远程扩展词典用于热词更新 elasticsearch-5.6.3/config/analysis-ik/IKAnalyzer.cfg.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd&quot;&gt;
<properties>
       <comment>IK Analyzer 扩展配置</comment>
       <!--用户可以在这里配置自己的扩展字典 -->
       <entry key="ext_dict"></entry>
        <!--用户可以在这里配置自己的扩展停止词字典-->
       <entry key="ext_stopwords"></entry>
       <!--用户可以在这里配置远程扩展字典 -->
       <entry key="remote_ext_dict">http://distribute.search.leju. ... gt%3B
       <!--用户可以在这里配置远程扩展停止词字典-->
       <!-- <entry key="remote_ext_stopwords">words_location</entry> -->
</properties>
安装拼音分词器

cd elasticsearch-5.5.1/plugins
wget https://github.com/medcl/elast ... 5.5.1
unzip v5.5.1




打包部署其他节点时,先清理data目录




集群监控可以利用head的chrome插件




数据迁移

迁移工具是自己写的elasticbak,目前更新了5.6.3驱动。github链接:https://github.com/jiashiwen/elasticbak

数据备份

java -jar elasticbak-2.3.3.jar \
--exp \
--cluster lejuesdev \
--host 10.204.12.31 \
--filesize 1000 \
--backupdir ./esbackupset \
--backupindexes "*" \
--threads 4
由于版本field的变化需要手工重建索引,这里举个例子,主要是2.x版本的string需要改为text。2.x版本我们通过index参数指定该字段是否被索引("index": "no")以及是否通过分词器分词("index": "not_analyzed")。在5.X版本里index只用来制定是否创建索引,如果需要整个字段不过分词器创建索引,需要通过keyword字段完成。  

 

curl -XPUT "http://10.204.12.31:9201/house_geo&quot; -H 'Content-Type: application/json' -d'
{
 "mappings": {
   "house": {
     "dynamic": "strict",
     "_all": {
       "enabled": false
     },
     "properties": {
       "_category": {
         "type": "keyword",
                 "store": true
       },
       "_content": {
         "type": "text",
         "store": true,
         "analyzer": "ik_max_word",
         "search_analyzer": "ik_smart"
       },
       "_deleted": {
         "type": "boolean",
         "store": true
       },
       "_doccreatetime": {
         "type": "date",
         "store": true,
         "format": "strict_date_optional_time||epoch_millis||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
       },
       "_docupdatetime": {
         "type": "date",
         "store": true,
         "format": "strict_date_optional_time||epoch_millis||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd"
       },
       "_flags": {
         "type": "text",
         "store": true,
         "analyzer": "whitespace"
       },
       "_hits": {
         "type": "text"
       },
       "_location": {
         "type": "geo_point"
       },
       "_multi": {
         "properties": {
           "_location": {
             "type": "geo_point"
           }
         }
       },
       "_origin": {
         "type": "object",
         "enabled": false
       },
       "_scope": {
         "type": "keyword",
         "store": true
       },
       "_tags": {
         "type": "text",
         "boost": 10,
         "store": true,
         "term_vector": "with_positions_offsets",
         "analyzer": "ik_max_word",
         "search_analyzer": "ik_smart"
       },
       "_title": {
         "type": "text",
         "store": true,
         "analyzer": "ik_max_word",
         "search_analyzer": "ik_smart"
       },
       "_uniqid": {
         "type": "keyword",
         "store": true
       },
       "_uniqsign": {
         "type": "keyword",
         "store": true
       },
       "_url": {
         "type": "text",
         "index": false,
         "store": true
       },
       "location": {
         "type": "geo_point"
       }
     }
   }
 },
 "settings": {
   "index": {
     "number_of_shards": "3",
     "requests": {
       "cache": {
         "enable": "true"
       }
     },
     "analysis": {
       "filter": {
         "my_synonym": {
           "type": "synonym",
           "synonyms_path": "analysis-ik/custom/synonym.dic"
         }
       },
       "analyzer": {
         "searchanalyzer": {
           "filter": "my_synonym",
           "type": "custom",
           "tokenizer": "ik_smart"
         },
         "indexanalyzer": {
           "filter": "my_synonym",
           "type": "custom",
           "tokenizer": "ik_max_word"
         }
       }
     },
     "number_of_replicas": "1"
   }
 }
}'
利用新版elasticbak导入索引数据


java -jar elasticbak-5.6.3.jar \
--imp \
--cluster es5_dev \
--host 10.204.12.31 \
--port 9301 \
--restoreindex house_geo \
--restoretype dataonly \
--backupset esbackupset/house_geo \
--threads 4
  收起阅读 »

社区日报 第99期 (2017-11-13)

1、使用于商业智能的复杂模型建模教程
http://t.cn/Rj2uLh9
2、logstash配置文件的vscode插件,从其编辑配置文件不再发愁。
http://t.cn/Rj21ncE
3、elk告警插件sentinl。随着版本的更新,目前已经可以媲美x-pack的reporter以及watcher。
http://t.cn/Rj216Ef
4、只等你来 | Elastic Meetup 广州交流会
https://elasticsearch.cn/article/364 

编辑:cyberdak
归档:https://elasticsearch.cn/article/372
订阅:https://tinyletter.com/elastic-daily
继续阅读 »
1、使用于商业智能的复杂模型建模教程
http://t.cn/Rj2uLh9
2、logstash配置文件的vscode插件,从其编辑配置文件不再发愁。
http://t.cn/Rj21ncE
3、elk告警插件sentinl。随着版本的更新,目前已经可以媲美x-pack的reporter以及watcher。
http://t.cn/Rj216Ef
4、只等你来 | Elastic Meetup 广州交流会
https://elasticsearch.cn/article/364 

编辑:cyberdak
归档:https://elasticsearch.cn/article/372
订阅:https://tinyletter.com/elastic-daily 收起阅读 »

社区日报 第98期 (2017-11-12)

1. (自备梯子)推荐三个数据库相关(MySQL,MongoDB,Elasticsearch)的课程。
http://t.cn/RjPvlq1
2. 将 ELASTICSEARCH 写入速度优化到极限
http://t.cn/RWs8yvS
3. 零点之战!探访阿里巴巴8大技术专家,提前揭秘2017双11关键技术。
http://t.cn/RjPPzGc
4. 只等你来 | Elastic Meetup 广州交流会
https://elasticsearch.cn/article/364

编辑:至尊宝
归档:https://elasticsearch.cn/article/371
订阅:https://tinyletter.com/elastic-daily
继续阅读 »
1. (自备梯子)推荐三个数据库相关(MySQL,MongoDB,Elasticsearch)的课程。
http://t.cn/RjPvlq1
2. 将 ELASTICSEARCH 写入速度优化到极限
http://t.cn/RWs8yvS
3. 零点之战!探访阿里巴巴8大技术专家,提前揭秘2017双11关键技术。
http://t.cn/RjPPzGc
4. 只等你来 | Elastic Meetup 广州交流会
https://elasticsearch.cn/article/364

编辑:至尊宝
归档:https://elasticsearch.cn/article/371
订阅:https://tinyletter.com/elastic-daily 收起阅读 »

三步上手 esrally 完成 elasticsearch 压测任务

原文链接

距离上一篇 esrally 教程过去快2个月了,这期间不停有同学来询问使用中遇到的问题,尤其由于其测试数据存储在国外 aws 上,导致下载极慢。为了让大家快速上手使用 esrally,我 build 了一个可用的 docker 镜像,然后将 13GB 的测试数据拉取到国内的存储上,通过百度网盘的方式分享给大家。大家只要按照下面简单的几步操作就可以顺畅地使用 esrally 来进行相关测试了。

操作步骤

废话不多说,先上菜!

  1. 拉取镜像
    docker pull rockybean/esrally
  2. 下载数据文件 链接:http://pan.baidu.com/s/1eSrjZgA 密码:aagl
  3. 进入下载后的文件夹 rally_track,执行如下命令开始测试
    docker run -it -v $(PWD):/root/track rockybean/esrally esrally race --track-path=/root/track/logging --offline --pipeline=benchmark-only --target-hosts=192.168.1.105:9200

打完收工!

几点说明

数据文件介绍

esrally 自带的测试数据即为 rally_track 文件夹中的内容,主要包括:

  • Geonames(geonames): for evaluating the performance of structured data.
  • Geopoint(geopoint): for evaluating the performance of geo queries.
  • Percolator(percolator): for evaluating the performance of percolation queries.
  • PMC(pmc): for evaluating the performance of full text search.
  • NYC taxis(nyc_taxis): for evaluating the performance for highly structured data.
  • Nested(nested): for evaluating the performance for nested documents.
  • Logging(logging): for evaluating the performance of (Web) server logs.
  • noaa(noaa): for evaluating the performance of range fields.

可以根据自己的需要下载对应的测试数据,不必下载全部,保证对应文件夹下载完全即可。

命令解释

docker 相关

docker run -it rockybean/esrally esrally 为执行的 esrally 命令,-v $(PWD):/root/track是将 rally_docker 文件夹映射到 docker 容器中,$(PWD)是获取当前目录的意思,所以在此前要 cd 到 rally_docker 目录,当然你写全路径也是没有问题的。

esrally 的 docker 镜像比较简单,可以参看 github 项目介绍

esrally 相关

该镜像是通过自定义 track 的方式来加载数据,所以命令行中用到 --track=/root/track/logging 的命令行参数。注意这里的 /root/track 即上面我们绑定到容器的目录,更换 logging 为其他的数据集名称即可加载其他的测试数据。

该容器只支持测试第三方 es 集群,即 --pipeline=benchmark-only 模式。这应该也是最常见的压测需求了。

愉快地去玩耍吧!

继续阅读 »

原文链接

距离上一篇 esrally 教程过去快2个月了,这期间不停有同学来询问使用中遇到的问题,尤其由于其测试数据存储在国外 aws 上,导致下载极慢。为了让大家快速上手使用 esrally,我 build 了一个可用的 docker 镜像,然后将 13GB 的测试数据拉取到国内的存储上,通过百度网盘的方式分享给大家。大家只要按照下面简单的几步操作就可以顺畅地使用 esrally 来进行相关测试了。

操作步骤

废话不多说,先上菜!

  1. 拉取镜像
    docker pull rockybean/esrally
  2. 下载数据文件 链接:http://pan.baidu.com/s/1eSrjZgA 密码:aagl
  3. 进入下载后的文件夹 rally_track,执行如下命令开始测试
    docker run -it -v $(PWD):/root/track rockybean/esrally esrally race --track-path=/root/track/logging --offline --pipeline=benchmark-only --target-hosts=192.168.1.105:9200

打完收工!

几点说明

数据文件介绍

esrally 自带的测试数据即为 rally_track 文件夹中的内容,主要包括:

  • Geonames(geonames): for evaluating the performance of structured data.
  • Geopoint(geopoint): for evaluating the performance of geo queries.
  • Percolator(percolator): for evaluating the performance of percolation queries.
  • PMC(pmc): for evaluating the performance of full text search.
  • NYC taxis(nyc_taxis): for evaluating the performance for highly structured data.
  • Nested(nested): for evaluating the performance for nested documents.
  • Logging(logging): for evaluating the performance of (Web) server logs.
  • noaa(noaa): for evaluating the performance of range fields.

可以根据自己的需要下载对应的测试数据,不必下载全部,保证对应文件夹下载完全即可。

命令解释

docker 相关

docker run -it rockybean/esrally esrally 为执行的 esrally 命令,-v $(PWD):/root/track是将 rally_docker 文件夹映射到 docker 容器中,$(PWD)是获取当前目录的意思,所以在此前要 cd 到 rally_docker 目录,当然你写全路径也是没有问题的。

esrally 的 docker 镜像比较简单,可以参看 github 项目介绍

esrally 相关

该镜像是通过自定义 track 的方式来加载数据,所以命令行中用到 --track=/root/track/logging 的命令行参数。注意这里的 /root/track 即上面我们绑定到容器的目录,更换 logging 为其他的数据集名称即可加载其他的测试数据。

该容器只支持测试第三方 es 集群,即 --pipeline=benchmark-only 模式。这应该也是最常见的压测需求了。

愉快地去玩耍吧!

收起阅读 »

sense不能用了改用kibana吧

elasticsearch的dsl开发工具sense被google下架了,kibana console是很好的替代品。但是,我们的es集群前些日子因为应付安全检查改为https+basic auth方式(详细配置过程见本人博文:http://blog.csdn.net/jiashiwen ... 14374),kibana需要进行若干配置才能工作。另外老系统中还有elasticsearch2.3.3遗留,需要kibana4.5.1+sense。




一、elasticsearch5.5.2+kibana5.5.2

1.下载与elasticsearch版本号一致的kibana安装包,笔者目前开发环境5.5.2,对应kibana版本也为5.5.2(最新的5.6版本会报不兼容错误,不能运行)。




2.配置config/kibana.yml文件,主要配置项如下 
# The URL of the Elasticsearch instance to use for all your queries.
#elasticsearch.url: "http://localhost:9200&quot;
elasticsearch.url: "https://192.168.1.1:9281/&quot;


# If your Elasticsearch is protected with basic authentication, these settings provide
# the username and password that the Kibana server uses to perform maintenance on the Kibana
# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# is proxied through the Kibana server.
#elasticsearch.username: "user"
#elasticsearch.password: "pass"
elasticsearch.username: "admin"
elasticsearch.password: "admin"


# Optional settings that provide the paths to the PEM-format SSL certificate and key files.
# These files validate that your Elasticsearch backend uses the same key files.
#elasticsearch.ssl.certificate: /path/to/your/client.crt
#elasticsearch.ssl.key: /path/to/your/client.key
elasticsearch.ssl.certificate: /home/develop/kibana-5.6.3-linux-x86_64/config/crts/eshttp.crt
elasticsearch.ssl.key: /home/develop/kibana-5.6.3-linux-x86_64/config/crts/eshttp.key


# To disregard the validity of SSL certificates, change this setting's value to 'none'.
#elasticsearch.ssl.verificationMode: full
elasticsearch.ssl.verificationMode: none各项配置看文件内说明,写的很清楚,这里就不翻译了,其中最重要的是这两样elasticsearch.ssl.certificate和elasticsearch.ssl.key,一定要与服务端保持一致。由于证书是自己生成的,校验项elasticsearch.ssl.verificationMode的值需要改为none。




启动kibana后,通过http://localhose:5601访问即可
继续阅读 »
elasticsearch的dsl开发工具sense被google下架了,kibana console是很好的替代品。但是,我们的es集群前些日子因为应付安全检查改为https+basic auth方式(详细配置过程见本人博文:http://blog.csdn.net/jiashiwen ... 14374),kibana需要进行若干配置才能工作。另外老系统中还有elasticsearch2.3.3遗留,需要kibana4.5.1+sense。




一、elasticsearch5.5.2+kibana5.5.2

1.下载与elasticsearch版本号一致的kibana安装包,笔者目前开发环境5.5.2,对应kibana版本也为5.5.2(最新的5.6版本会报不兼容错误,不能运行)。




2.配置config/kibana.yml文件,主要配置项如下 
# The URL of the Elasticsearch instance to use for all your queries.
#elasticsearch.url: "http://localhost:9200&quot;
elasticsearch.url: "https://192.168.1.1:9281/&quot;


# If your Elasticsearch is protected with basic authentication, these settings provide
# the username and password that the Kibana server uses to perform maintenance on the Kibana
# index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
# is proxied through the Kibana server.
#elasticsearch.username: "user"
#elasticsearch.password: "pass"
elasticsearch.username: "admin"
elasticsearch.password: "admin"


# Optional settings that provide the paths to the PEM-format SSL certificate and key files.
# These files validate that your Elasticsearch backend uses the same key files.
#elasticsearch.ssl.certificate: /path/to/your/client.crt
#elasticsearch.ssl.key: /path/to/your/client.key
elasticsearch.ssl.certificate: /home/develop/kibana-5.6.3-linux-x86_64/config/crts/eshttp.crt
elasticsearch.ssl.key: /home/develop/kibana-5.6.3-linux-x86_64/config/crts/eshttp.key


# To disregard the validity of SSL certificates, change this setting's value to 'none'.
#elasticsearch.ssl.verificationMode: full
elasticsearch.ssl.verificationMode: none各项配置看文件内说明,写的很清楚,这里就不翻译了,其中最重要的是这两样elasticsearch.ssl.certificate和elasticsearch.ssl.key,一定要与服务端保持一致。由于证书是自己生成的,校验项elasticsearch.ssl.verificationMode的值需要改为none。




启动kibana后,通过http://localhose:5601访问即可 收起阅读 »

社区日报 第97期 (2017-11-11)

  1. sense为什么不能用了,看看ES官方怎么说? http://t.cn/RlB3B62

  2. 使用allocation API快速定位分片分配问题 http://t.cn/RlrzTsD

  3. ES6.0有关防止硬盘被填满的改进 http://t.cn/RlrU3Nr

  4. 喜大普奔,ES社区支持Markdown编辑器了 https://elasticsearch.cn/article/366

  5. Elastic 收购网站搜索 SaaS 服务领导者 Swiftype http://t.cn/Rl3a4P2

  6. 只等你来 | Elastic Meetup 广州交流会 https://elasticsearch.cn/article/364
继续阅读 »
  1. sense为什么不能用了,看看ES官方怎么说? http://t.cn/RlB3B62

  2. 使用allocation API快速定位分片分配问题 http://t.cn/RlrzTsD

  3. ES6.0有关防止硬盘被填满的改进 http://t.cn/RlrU3Nr

  4. 喜大普奔,ES社区支持Markdown编辑器了 https://elasticsearch.cn/article/366

  5. Elastic 收购网站搜索 SaaS 服务领导者 Swiftype http://t.cn/Rl3a4P2

  6. 只等你来 | Elastic Meetup 广州交流会 https://elasticsearch.cn/article/364
收起阅读 »