Easysearch、Elasticsearch 还是 Opensearch,是个问题

Elasticsearch 5.4 发布,新增机器学习功能

出大事了,Elastic Stack 今日发布 5.4 版本,X-Pack 新增机器学习模块!
https://www.elastic.co/cn/blog ... stack
 今天,我们非常荣幸地宣布,首次发布通过 X-Pack 提供的 Elastic Stack Machine Learning 功能。加入 Elastic 就像跳上了火箭船,但是经过 7 个月不可思议的工作,我们现已将 Prelert Machine Learning 技术完全集成到 Elastic Stack。这让我们很激动,而且我们非常迫切地想要收到用户的反馈。

温馨提示:请注意,不要太过激动,这项功能在 5.4.0 版本中尚标记为 beta。

Machine Learning

我们的目标是通过一系列工具为用户赋能,让他们可以从自己的 Elasticsearch 数据中获取价值和洞察。与此同时,我们将 Machine Learning 视为 Elasticsearch 搜索和分析能力的自然延伸。举例来说,Elasticsearch 能够让您在大量数据中,实时地搜索用户“steve”的交易,或者利用聚合和可视化,展示一段时间以来的十大畅销产品或交易趋势。而现在有了 Machine Learning 功能,您就可以更加深入地探究数据,例如 “有没有哪项服务的行为发生了变化?” 或者 “主机上是否运行有异常进程?” 那么要想回答这些问题,就必须要利用 Machine Learning 技术,通过数据自动构建主机或服务的行为模式。

不过, Machine Learning 目前是软件行业最被夸大其词的术语之一,因为从本质上来讲,它就是用来实现数据驱动型预测、决策和建模的一系列广泛的算法和方法。因此,我们有必要隔绝干扰信息,具体说说我们所做的工作。

时间序列异常检测

目前,X-Pack Machine Learning 功能的着眼点是,利用无监督式机器学习,提供 “时间序列异常检测” 功能。

随着时间的推移,我们计划增加更多 Machine Learning 功能,但是我们目前只专注于为用户存储的时间序列数据(例如日志文件、应用程序和性能指标、网络流量或 Elasticsearch 中的财务/交易数据)提供附加值。

示例 1 - 自动提醒关键绩效指标值的异常变化

要说这项技术最直观的用例,那就是可以识别指标值或事件速率偏离正常行为的情况。例如,服务响应时间有没有显著增加?网站访客预期数量与同一时段正常情况相比,是否存在明显差异?传统情况下,人们会利用规则、阈值或简单的统计方法来进行此类分析。但遗憾的是,这些简单的方法鲜少能够高效地处理实际数据,原因在于此类方法往往是基于无效的统计假设(例如:高斯分布),因此不支持趋势分析(长期性或周期性趋势),或者在信号发生变化时缺乏稳定性。

所以说, Machine Learning 功能的首个切入点是单一指标作业,您可以借此了解该产品如何学习正常模式,如何识别单变量时间序列数据中存在的异常。如果您发现的异常是有意义的,您就可以连续地实时运行这项分析,并在发生异常时发出警报。

尽管这看上去像是一个比较简单的用例,但是产品后台包含大量复杂的无监督式机器学习算法和统计模型,因此我们对于任意信号具有鲁棒性,并且能够准确反映。

此外,为了让该功能可以在 Elasticsearch 集群中像原生程序一样运行,我们对功能实现进行了优化,因此几秒钟即可分析数以百万计的事件。

machine-learning-1.gif



示例 2 - 自动追踪数以千计的指标

Machine Learning 产品可以扩展到数十万指标和日志文件,那么下一步就是要同时分析多个指标。这些指标可能是来自同一个主机的多个相关指标,可能是来自同一个数据库或应用程序的性能指标,也可能是来自多个主机的多个日志文件。在这种情况下,我们可以直接单独分析,再将结果聚合到同一个窗口,展示整体的系统异常情况。

例如,假设我要处理来自一大组应用程序服务的响应时间,我可以直接分析各个服务一段时间以来的响应时间,分别确认各个行为异常的服务,同时展示整体的系统异常情况:

machine-learning-2-1.gif


示例 3 - 高级作业

最后,我们的产品还有大量更高级的用途。比方说,如果您想找出与整体相比行为异常的用户、异常的 DNS 流量,或者伦敦街头的拥堵路段,这时您就可以利用高级作业,灵活地分析 Elasticsearch 中存储的任何时间序列数据。

Elastic Stack 整合

Machine Learning 是 X-Pack 中的一项功能。这就意味着,安装 X-Pack 之后,就可以使用 Machine Learning 功能实时分析 Elasticsearch 中的时间序列数据。 Machine Learning 作业与索引和分片基本类似,能够跨 Elasticsearch 集群自动分布和管理。这还意味着 Machine Learning 作业对节点故障有很好的适应性。从性能角度看,紧密集成意味着数据永远不需要离开集群,而且我们可以利用 Elasticsearch 聚合极大地提高某些作业类型的性能。而紧密集成带来的另外一个好处就是,您可以直接从 Kibana 创建异常检测作业并查看结果。

由于这种方法对数据进行原位分析,数据从不离开集群,因此与将 Elasticsearch 数据集成到外部数据科学工具相比,这种方法能够带来显著的性能和运维优势。随着我们在这个领域开发出越来越多的技术,这种架构的优势将会更加显著。


blog-machine-learning-5-4-release.png



立即试用并反馈

这些 Machine Learning 功能是 X-Pack 5.4 中的 beta 功能,现已可用。我们急切地想要听听您的使用体会,所以请下载 5.4 版本,安装 X-Pack,然后直接联系我们,或者通过我们的讨论论坛联系我们。
下载地址:https://www.elastic.co/cn/downloads
 
继续阅读 »
出大事了,Elastic Stack 今日发布 5.4 版本,X-Pack 新增机器学习模块!
https://www.elastic.co/cn/blog ... stack
 今天,我们非常荣幸地宣布,首次发布通过 X-Pack 提供的 Elastic Stack Machine Learning 功能。加入 Elastic 就像跳上了火箭船,但是经过 7 个月不可思议的工作,我们现已将 Prelert Machine Learning 技术完全集成到 Elastic Stack。这让我们很激动,而且我们非常迫切地想要收到用户的反馈。

温馨提示:请注意,不要太过激动,这项功能在 5.4.0 版本中尚标记为 beta。

Machine Learning

我们的目标是通过一系列工具为用户赋能,让他们可以从自己的 Elasticsearch 数据中获取价值和洞察。与此同时,我们将 Machine Learning 视为 Elasticsearch 搜索和分析能力的自然延伸。举例来说,Elasticsearch 能够让您在大量数据中,实时地搜索用户“steve”的交易,或者利用聚合和可视化,展示一段时间以来的十大畅销产品或交易趋势。而现在有了 Machine Learning 功能,您就可以更加深入地探究数据,例如 “有没有哪项服务的行为发生了变化?” 或者 “主机上是否运行有异常进程?” 那么要想回答这些问题,就必须要利用 Machine Learning 技术,通过数据自动构建主机或服务的行为模式。

不过, Machine Learning 目前是软件行业最被夸大其词的术语之一,因为从本质上来讲,它就是用来实现数据驱动型预测、决策和建模的一系列广泛的算法和方法。因此,我们有必要隔绝干扰信息,具体说说我们所做的工作。

时间序列异常检测

目前,X-Pack Machine Learning 功能的着眼点是,利用无监督式机器学习,提供 “时间序列异常检测” 功能。

随着时间的推移,我们计划增加更多 Machine Learning 功能,但是我们目前只专注于为用户存储的时间序列数据(例如日志文件、应用程序和性能指标、网络流量或 Elasticsearch 中的财务/交易数据)提供附加值。

示例 1 - 自动提醒关键绩效指标值的异常变化

要说这项技术最直观的用例,那就是可以识别指标值或事件速率偏离正常行为的情况。例如,服务响应时间有没有显著增加?网站访客预期数量与同一时段正常情况相比,是否存在明显差异?传统情况下,人们会利用规则、阈值或简单的统计方法来进行此类分析。但遗憾的是,这些简单的方法鲜少能够高效地处理实际数据,原因在于此类方法往往是基于无效的统计假设(例如:高斯分布),因此不支持趋势分析(长期性或周期性趋势),或者在信号发生变化时缺乏稳定性。

所以说, Machine Learning 功能的首个切入点是单一指标作业,您可以借此了解该产品如何学习正常模式,如何识别单变量时间序列数据中存在的异常。如果您发现的异常是有意义的,您就可以连续地实时运行这项分析,并在发生异常时发出警报。

尽管这看上去像是一个比较简单的用例,但是产品后台包含大量复杂的无监督式机器学习算法和统计模型,因此我们对于任意信号具有鲁棒性,并且能够准确反映。

此外,为了让该功能可以在 Elasticsearch 集群中像原生程序一样运行,我们对功能实现进行了优化,因此几秒钟即可分析数以百万计的事件。

machine-learning-1.gif



示例 2 - 自动追踪数以千计的指标

Machine Learning 产品可以扩展到数十万指标和日志文件,那么下一步就是要同时分析多个指标。这些指标可能是来自同一个主机的多个相关指标,可能是来自同一个数据库或应用程序的性能指标,也可能是来自多个主机的多个日志文件。在这种情况下,我们可以直接单独分析,再将结果聚合到同一个窗口,展示整体的系统异常情况。

例如,假设我要处理来自一大组应用程序服务的响应时间,我可以直接分析各个服务一段时间以来的响应时间,分别确认各个行为异常的服务,同时展示整体的系统异常情况:

machine-learning-2-1.gif


示例 3 - 高级作业

最后,我们的产品还有大量更高级的用途。比方说,如果您想找出与整体相比行为异常的用户、异常的 DNS 流量,或者伦敦街头的拥堵路段,这时您就可以利用高级作业,灵活地分析 Elasticsearch 中存储的任何时间序列数据。

Elastic Stack 整合

Machine Learning 是 X-Pack 中的一项功能。这就意味着,安装 X-Pack 之后,就可以使用 Machine Learning 功能实时分析 Elasticsearch 中的时间序列数据。 Machine Learning 作业与索引和分片基本类似,能够跨 Elasticsearch 集群自动分布和管理。这还意味着 Machine Learning 作业对节点故障有很好的适应性。从性能角度看,紧密集成意味着数据永远不需要离开集群,而且我们可以利用 Elasticsearch 聚合极大地提高某些作业类型的性能。而紧密集成带来的另外一个好处就是,您可以直接从 Kibana 创建异常检测作业并查看结果。

由于这种方法对数据进行原位分析,数据从不离开集群,因此与将 Elasticsearch 数据集成到外部数据科学工具相比,这种方法能够带来显著的性能和运维优势。随着我们在这个领域开发出越来越多的技术,这种架构的优势将会更加显著。


blog-machine-learning-5-4-release.png



立即试用并反馈

这些 Machine Learning 功能是 X-Pack 5.4 中的 beta 功能,现已可用。我们急切地想要听听您的使用体会,所以请下载 5.4 版本,安装 X-Pack,然后直接联系我们,或者通过我们的讨论论坛联系我们。
下载地址:https://www.elastic.co/cn/downloads
  收起阅读 »

Elasticsearch 6.0 将移除 Type

尽管之前在很多地方都提到过,不过还是有必要单独开篇文章提醒一下大家!
Type 已经打算在6.0移除了,所以在设计 elasticsearch 的数据结构的时候,要注意到后面版本的变化。
之前在很多的文章和 PPT 都有介绍Elasticsearch 的几个核心概念,Index 对应 DB,Type 对应表,Document 对应记录,然后就真的按数据库的路子用,一个 index 里面 n 个 type 的情况大有存在,但是在 Lucene 里面其实有很多问题,所以现在es移除也是考虑了很久的。

新增参数:
index.mapping.single_type: true
 
UID 也会移除掉 _type 的值。

Type 移除大概分为两个阶段:
第一步,不支持新的索引创建多个 type,一个索引只有一个 type,名称也是固定的,不能修改。
第二步,移除。
 
相应的 PR 已经 merge 了。
https://github.com/elastic/ela ... 24317
 
继续阅读 »
尽管之前在很多地方都提到过,不过还是有必要单独开篇文章提醒一下大家!
Type 已经打算在6.0移除了,所以在设计 elasticsearch 的数据结构的时候,要注意到后面版本的变化。
之前在很多的文章和 PPT 都有介绍Elasticsearch 的几个核心概念,Index 对应 DB,Type 对应表,Document 对应记录,然后就真的按数据库的路子用,一个 index 里面 n 个 type 的情况大有存在,但是在 Lucene 里面其实有很多问题,所以现在es移除也是考虑了很久的。

新增参数:
index.mapping.single_type: true
 
UID 也会移除掉 _type 的值。

Type 移除大概分为两个阶段:
第一步,不支持新的索引创建多个 type,一个索引只有一个 type,名称也是固定的,不能修改。
第二步,移除。
 
相应的 PR 已经 merge 了。
https://github.com/elastic/ela ... 24317
  收起阅读 »

社区网站更新日志

这里专门用来放社区网站更新的日志。
 
  • 2017.4.28 支持 SSL

Snip20170428_1.png

 
这里专门用来放社区网站更新的日志。
 
  • 2017.4.28 支持 SSL

Snip20170428_1.png

 

Sql on Elasticsearch

esql
Git地址
https://github.com/unimassystem/esql5 

elsh.png

 
create table my_index.my_table (
id keyword,
name text,
age long,
birthday date
);

select * from my_index.my_type;

select count(*) from my_index.my_table group by age;
#Create table

字段参数,ES中分词规则、索引类型、字段格式等高级参数的支持

create table my_table (
name text (analyzer = ik_max_word),
dd text (index=no),
age long (include_in_all=false)
);


对象、嵌套字段支持 as

create table my_index (
id long,
name text,
obj object as (
first_name text,
second_name text (analyzer=pinyin)
)
);


create table my_index (
id long,
name text,
obj nested as (
first_name text,
second_name text (analyzer=pinyin)
)
);


ES索引高级参数支持 with option

create table my_index (
id long,
name text
) with option (
index.number_of_shards=10,
index.number_of_replicas = 1
);
#Insert/Bulk

单条数据插入
insert into my_index.index (name,age) values ('zhangsan',24);

多条插入
bulk into my_index.index (name,age) values ('zhangsan',24),('lisi',24);


对象数据插入,list,{}Map

insert into my_index.index (ds) values (['zhejiang','hangzhou']);

insert into my_index.index (dd) values ({address='zhejiang',postCode='330010'});
#select/Aggregations

select * from my_table.my_index where name like 'john *' and age between 20 and 30 and (hotel = 'hanting' or flight = 'MH4510');

地理位置中心点查询
select * from hz_point where geo_distance({distance='1km',location='30.306378,120.247427'});

地理坐标区域查询
select * from hz_point where geo_bounding_box({location={top_left='31.306378,119.247427',bottom_right='29.285797,122.172329'}});

pipeline统计 move_avg
select count(*) as total, moving_avg({buckets_path=total}) from my_index group by date_histogram({field=timestamp,interval='1h'});
Getting Started

环境要求python >= 2.7

export PYTHONHOME=(%python_path)
export PATH=$PYTHONHOME/bin:$PATH


安装第三方依赖包
pip install -r esql5.egg-info/requires.txt
或python setup.py install

运行esql5服务
(standalone):
cd esql5
python -m App.app

(with uwsgi)
cd esql5
uwsgi --ini conf/uwsgi.ini


shell终端:
python -m elsh.Command
继续阅读 »
esql
Git地址
https://github.com/unimassystem/esql5 

elsh.png

 
create table my_index.my_table (
id keyword,
name text,
age long,
birthday date
);

select * from my_index.my_type;

select count(*) from my_index.my_table group by age;
#Create table

字段参数,ES中分词规则、索引类型、字段格式等高级参数的支持

create table my_table (
name text (analyzer = ik_max_word),
dd text (index=no),
age long (include_in_all=false)
);


对象、嵌套字段支持 as

create table my_index (
id long,
name text,
obj object as (
first_name text,
second_name text (analyzer=pinyin)
)
);


create table my_index (
id long,
name text,
obj nested as (
first_name text,
second_name text (analyzer=pinyin)
)
);


ES索引高级参数支持 with option

create table my_index (
id long,
name text
) with option (
index.number_of_shards=10,
index.number_of_replicas = 1
);
#Insert/Bulk

单条数据插入
insert into my_index.index (name,age) values ('zhangsan',24);

多条插入
bulk into my_index.index (name,age) values ('zhangsan',24),('lisi',24);


对象数据插入,list,{}Map

insert into my_index.index (ds) values (['zhejiang','hangzhou']);

insert into my_index.index (dd) values ({address='zhejiang',postCode='330010'});
#select/Aggregations

select * from my_table.my_index where name like 'john *' and age between 20 and 30 and (hotel = 'hanting' or flight = 'MH4510');

地理位置中心点查询
select * from hz_point where geo_distance({distance='1km',location='30.306378,120.247427'});

地理坐标区域查询
select * from hz_point where geo_bounding_box({location={top_left='31.306378,119.247427',bottom_right='29.285797,122.172329'}});

pipeline统计 move_avg
select count(*) as total, moving_avg({buckets_path=total}) from my_index group by date_histogram({field=timestamp,interval='1h'});
Getting Started

环境要求python >= 2.7

export PYTHONHOME=(%python_path)
export PATH=$PYTHONHOME/bin:$PATH


安装第三方依赖包
pip install -r esql5.egg-info/requires.txt
或python setup.py install

运行esql5服务
(standalone):
cd esql5
python -m App.app

(with uwsgi)
cd esql5
uwsgi --ini conf/uwsgi.ini


shell终端:
python -m elsh.Command
收起阅读 »

用logstash导入ES且自定义mapping时踩的坑

问题发生背景:

1.本来我是使用logstash的默认配置向ES导入日志的。然后很嗨皮,发现一切OK,后来我开始对日志进行聚合统计,发现terms聚合时的key很奇怪,后来查询这奇怪的key,发现这些关键字都是源字符串的一段,而且全部复现场景都是出现"xxxx-xxxxxx"时就会截断,感觉像是分词器搞的鬼。所以想自己定制mapping。下面是原来的logstash配置
output{
elasticsearch{
action => "index"
hosts => ["xxxxxx:9200"]
index => "xxxxx"
document_type => "haha"
}
}



说干就干:

开始四处查阅文档,发现可以定制mapping,很开心。
output{
elasticsearch{
action => "index"
hosts => ["xxx"]
index => "logstashlog"
template => "xx/http-logstash.json"
template_name => "http-log-logstash"
template_overwrite => true
}
stdout{
codec => rubydebug
}

}没有什么一帆风顺:
问题1:
但是我发现我已经上传了自定义的template,但是就是不能生效。
这时知道了,这个要设置order才能覆盖,默认的order是0,必须更大才行,参考
http://elasticsearch.cn/article/21
问题2:
我看到自己上传的template的order已经是1了,怎么还是不生效呢?
原来自己的索引名称不匹配自己的template的名称,所以不能使用,就又用了默认的template。
改成下面后OK,终于生效了。(注意index名称变化)output{
elasticsearch{
action => "index"
hosts => ["xxx"]
index => "http-log-logstash"
document_type => "haha"
template => "xxx/http-logstash.json"
template_name => "http-log-logstash"
template_overwrite => true
}
stdout{
codec => rubydebug
}

}问题3:
发现导入失败,原来自己的时间字符串不能用默认的date的format匹配,
如2017-04-11 00:07:25   不能用 { "type" : "date"} 的默认format匹配,
改成:"format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"}, 
这样就能解析了。
一切OK,谢谢社区,谢谢Google(你是我见过的除了书籍和老师之后最提升生产力的工具)

附上我的模板
{ 
"template" : "qmpsearchlog",
"order":1,
"settings" : { "index.refresh_interval" : "60s" },
"mappings" : {
"_default_" : {
"_all" : { "enabled" : false },
"dynamic_templates" : [{
"message_field" : {
"match" : "message",
"match_mapping_type" : "string",
"mapping" : { "type" : "string", "index" : "not_analyzed" }
}
}, {
"string_fields" : {
"match" : "*",
"match_mapping_type" : "string",
"mapping" : { "type" : "string", "index" : "not_analyzed" }
}
}],
"properties" : {
"@timestamp" : { "type" : "date"},
"@version" : { "type" : "integer", "index" : "not_analyzed" },
"path" : { "type" : "string", "index" : "not_analyzed" },
"host" : { "type" : "string", "index" : "not_analyzed" },
"record_time":{"type":"date","format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
"method":{"type":"string","index" : "not_analyzed"},
"unionid":{"type":"string","index" : "not_analyzed"},
"user_name":{"type":"string","index" : "not_analyzed"},
"query":{"type":"string","index" : "not_analyzed"},
"ip":{ "type" : "ip"},
"webbrower":{"type":"string","index" : "not_analyzed"},
"os":{"type":"string","index" : "not_analyzed"},
"device":{"type":"string","index" : "not_analyzed"},
"ptype":{"type":"string","index" : "not_analyzed"},
"serarch_time":{"type":"date","format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
"have_ok":{"type":"string","index" : "not_analyzed"},
"legal":{"type":"string","index" : "not_analyzed"}
}
}
}
}



 
继续阅读 »
问题发生背景:

1.本来我是使用logstash的默认配置向ES导入日志的。然后很嗨皮,发现一切OK,后来我开始对日志进行聚合统计,发现terms聚合时的key很奇怪,后来查询这奇怪的key,发现这些关键字都是源字符串的一段,而且全部复现场景都是出现"xxxx-xxxxxx"时就会截断,感觉像是分词器搞的鬼。所以想自己定制mapping。下面是原来的logstash配置
output{
elasticsearch{
action => "index"
hosts => ["xxxxxx:9200"]
index => "xxxxx"
document_type => "haha"
}
}



说干就干:

开始四处查阅文档,发现可以定制mapping,很开心。
output{
elasticsearch{
action => "index"
hosts => ["xxx"]
index => "logstashlog"
template => "xx/http-logstash.json"
template_name => "http-log-logstash"
template_overwrite => true
}
stdout{
codec => rubydebug
}

}没有什么一帆风顺:
问题1:
但是我发现我已经上传了自定义的template,但是就是不能生效。
这时知道了,这个要设置order才能覆盖,默认的order是0,必须更大才行,参考
http://elasticsearch.cn/article/21
问题2:
我看到自己上传的template的order已经是1了,怎么还是不生效呢?
原来自己的索引名称不匹配自己的template的名称,所以不能使用,就又用了默认的template。
改成下面后OK,终于生效了。(注意index名称变化)output{
elasticsearch{
action => "index"
hosts => ["xxx"]
index => "http-log-logstash"
document_type => "haha"
template => "xxx/http-logstash.json"
template_name => "http-log-logstash"
template_overwrite => true
}
stdout{
codec => rubydebug
}

}问题3:
发现导入失败,原来自己的时间字符串不能用默认的date的format匹配,
如2017-04-11 00:07:25   不能用 { "type" : "date"} 的默认format匹配,
改成:"format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"}, 
这样就能解析了。
一切OK,谢谢社区,谢谢Google(你是我见过的除了书籍和老师之后最提升生产力的工具)

附上我的模板
{ 
"template" : "qmpsearchlog",
"order":1,
"settings" : { "index.refresh_interval" : "60s" },
"mappings" : {
"_default_" : {
"_all" : { "enabled" : false },
"dynamic_templates" : [{
"message_field" : {
"match" : "message",
"match_mapping_type" : "string",
"mapping" : { "type" : "string", "index" : "not_analyzed" }
}
}, {
"string_fields" : {
"match" : "*",
"match_mapping_type" : "string",
"mapping" : { "type" : "string", "index" : "not_analyzed" }
}
}],
"properties" : {
"@timestamp" : { "type" : "date"},
"@version" : { "type" : "integer", "index" : "not_analyzed" },
"path" : { "type" : "string", "index" : "not_analyzed" },
"host" : { "type" : "string", "index" : "not_analyzed" },
"record_time":{"type":"date","format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
"method":{"type":"string","index" : "not_analyzed"},
"unionid":{"type":"string","index" : "not_analyzed"},
"user_name":{"type":"string","index" : "not_analyzed"},
"query":{"type":"string","index" : "not_analyzed"},
"ip":{ "type" : "ip"},
"webbrower":{"type":"string","index" : "not_analyzed"},
"os":{"type":"string","index" : "not_analyzed"},
"device":{"type":"string","index" : "not_analyzed"},
"ptype":{"type":"string","index" : "not_analyzed"},
"serarch_time":{"type":"date","format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"},
"have_ok":{"type":"string","index" : "not_analyzed"},
"legal":{"type":"string","index" : "not_analyzed"}
}
}
}
}



  收起阅读 »

社区网站服务器迁移完毕

image001.png

 感谢 ConvertLab 为本站提供服务器,目前服务器已经迁移完毕,大家可以感受一下速度!

 
logoblack.png

同时感谢在此之前为本站提供网站空间的:谱时 
 
 
社区账号也支持 Github 绑定了。

感谢大家一路支持,社区有你更精彩。
继续阅读 »
image001.png

 感谢 ConvertLab 为本站提供服务器,目前服务器已经迁移完毕,大家可以感受一下速度!

 
logoblack.png

同时感谢在此之前为本站提供网站空间的:谱时 
 
 
社区账号也支持 Github 绑定了。

感谢大家一路支持,社区有你更精彩。 收起阅读 »

ELK学习资料整理

刚开始学习使用ELK,整理一个学习资料列表,当做备忘录。
 
1.第一个当然是官方文档
  • ElasticSearch参考手册,学习 DSL查询语法,包括查找(query)、过滤(filter)和聚合(aggs)等。
  • Logstash参考手册,学习数据导入,包括输入(input)、过滤(filter)和输出( output)等,主要是filter中如何对复杂文本 进行拆分和类型 转化。
  • Kibana参考手册,使用Kibana提供的前端界面对数据进行快速展示,主要是对Visulize 模块的使

2.中文文档

 
欢迎补充……
继续阅读 »
刚开始学习使用ELK,整理一个学习资料列表,当做备忘录。
 
1.第一个当然是官方文档
  • ElasticSearch参考手册,学习 DSL查询语法,包括查找(query)、过滤(filter)和聚合(aggs)等。
  • Logstash参考手册,学习数据导入,包括输入(input)、过滤(filter)和输出( output)等,主要是filter中如何对复杂文本 进行拆分和类型 转化。
  • Kibana参考手册,使用Kibana提供的前端界面对数据进行快速展示,主要是对Visulize 模块的使

2.中文文档

 
欢迎补充…… 收起阅读 »

logstash多时间(date)字段文档导入

我们都知道如果文档中有表示时间的字段时可以用如下方法将字段转化为date(timestamp)格式导入
date {
match => [ "submission_time", "yyyyMMdd" ]
}
但是如果一条记录中有多个字段需要使用date类型呢?有人遇到了 同样的问题How to parse multiple date fields?其实多次使用date{}语法就行了,例如:
date {
match => [ "submission_time", "UNIX_MS" ]
target => "@timestamp"
}
date {
match => [ "submission_time", "UNIX_MS" ]
target => "submission_time"
}
date {
match => [ "start_time", "UNIX_MS" ]
target => "start_time"
}
date {
match => [ "end_time", "UNIX_MS" ]
target => "end_time"
}
查看官方文档后, 发现一直使用的date是省去了参数target的,而target默认值为@timestamp。
继续阅读 »
我们都知道如果文档中有表示时间的字段时可以用如下方法将字段转化为date(timestamp)格式导入
date {
match => [ "submission_time", "yyyyMMdd" ]
}
但是如果一条记录中有多个字段需要使用date类型呢?有人遇到了 同样的问题How to parse multiple date fields?其实多次使用date{}语法就行了,例如:
date {
match => [ "submission_time", "UNIX_MS" ]
target => "@timestamp"
}
date {
match => [ "submission_time", "UNIX_MS" ]
target => "submission_time"
}
date {
match => [ "start_time", "UNIX_MS" ]
target => "start_time"
}
date {
match => [ "end_time", "UNIX_MS" ]
target => "end_time"
}
查看官方文档后, 发现一直使用的date是省去了参数target的,而target默认值为@timestamp。 收起阅读 »

ES节点memory lock重要性与实现方式

看一下Elastic官网对开启 bootstrap.memory_lock的介绍:
 
Swapping is very bad for performance and for node stability and should be avoided at all costs. It can cause garbage collections to last for minutes instead of milliseconds and can cause nodes to respond slowly or even to disconnect from the cluster.                                                                   ----截取自官网


意思是说发生系统swapping的时候ES节点的性能会非常差,也会影响节点的稳定性。所以要不惜一切代价来避免swapping。swapping会导致Java GC的周期延迟从毫秒级恶化到分钟,更严重的是会引起节点响应延迟甚至脱离集群。                                                                      ----如果不了解到底什么是swapping的,可以找点Linux IO章节文章看看


 
1. 先检查一下你的各个ES节点是否开启了Mem_lock


GET 请求 /_nodes?filter_path=**.mlockall



{
  "nodes": {
    "dCH5FCpATRO7D1azyPhsRQ": {
      "process": {
        "mlockall": false
      }
    },
    "GoNfwnNzSwmJy3y1QdfluA": {
      "process": {
        "mlockall": false
      }
    },
    "ijW61kA-SAqnnVHjpTSw2w": {
      "process": {
        "mlockall": false
      }
    },
    "yHl9GUGbS46o4hwKvHpwnQ": {
      "process": {
        "mlockall": false
      }
    }
  }
}


上述返回内容,可见都没有开启mem_lock,集全随时都可能发生故障(尤其是集群正常运行了一段时间,莫名其妙的故障)
 
2. root权限执行ulimit -l unlimited


告诉操作系统可以无限制分配内存给一个进程


3.重新启动ES


[2017-04-06T11:51:14,840][INFO ][o.e.b.BootstrapCheck     ] [Portal_ES_Node10_0_36_49] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: bootstrap checks failed
memory locking requested for elasticsearch process but memory is not locked


 
4. 如果你遇到上面的错误,说明你还需要配置/etc/security/limits.conf
    增加下面3行到文件末尾,其中XXX表示当前用户


# allow user 'XXX' mlockall
XXX soft memlock unlimited
XXX hard memlock unlimited


继续阅读 »
看一下Elastic官网对开启 bootstrap.memory_lock的介绍:
 
Swapping is very bad for performance and for node stability and should be avoided at all costs. It can cause garbage collections to last for minutes instead of milliseconds and can cause nodes to respond slowly or even to disconnect from the cluster.                                                                   ----截取自官网


意思是说发生系统swapping的时候ES节点的性能会非常差,也会影响节点的稳定性。所以要不惜一切代价来避免swapping。swapping会导致Java GC的周期延迟从毫秒级恶化到分钟,更严重的是会引起节点响应延迟甚至脱离集群。                                                                      ----如果不了解到底什么是swapping的,可以找点Linux IO章节文章看看


 
1. 先检查一下你的各个ES节点是否开启了Mem_lock


GET 请求 /_nodes?filter_path=**.mlockall



{
  "nodes": {
    "dCH5FCpATRO7D1azyPhsRQ": {
      "process": {
        "mlockall": false
      }
    },
    "GoNfwnNzSwmJy3y1QdfluA": {
      "process": {
        "mlockall": false
      }
    },
    "ijW61kA-SAqnnVHjpTSw2w": {
      "process": {
        "mlockall": false
      }
    },
    "yHl9GUGbS46o4hwKvHpwnQ": {
      "process": {
        "mlockall": false
      }
    }
  }
}


上述返回内容,可见都没有开启mem_lock,集全随时都可能发生故障(尤其是集群正常运行了一段时间,莫名其妙的故障)
 
2. root权限执行ulimit -l unlimited


告诉操作系统可以无限制分配内存给一个进程


3.重新启动ES


[2017-04-06T11:51:14,840][INFO ][o.e.b.BootstrapCheck     ] [Portal_ES_Node10_0_36_49] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: bootstrap checks failed
memory locking requested for elasticsearch process but memory is not locked


 
4. 如果你遇到上面的错误,说明你还需要配置/etc/security/limits.conf
    增加下面3行到文件末尾,其中XXX表示当前用户


# allow user 'XXX' mlockall
XXX soft memlock unlimited
XXX hard memlock unlimited


收起阅读 »

做为接入方,你的痛点是什么?

希望大家踊跃发言。
希望大家踊跃发言。

100种让ES宕机的方法,请详细描述过程,且可复现的。

大家好,最近这个客题需要大家的帮忙啦,后面会专门录个视频来汇总讲解这些 bad case.
 
OOM:
  方式1:
       版本: all
       深度分页和大数据量数据返回会导致OOM。  
  方式2:
       版本: es 1.x
       使用delete_by_query删除海量数据时,由于内部没有使用scroll模块,会由深度分页导致OOM
  方式3:
       版本: all
       使用scroll返回大量数据导致OOM
 
继续阅读 »
大家好,最近这个客题需要大家的帮忙啦,后面会专门录个视频来汇总讲解这些 bad case.
 
OOM:
  方式1:
       版本: all
       深度分页和大数据量数据返回会导致OOM。  
  方式2:
       版本: es 1.x
       使用delete_by_query删除海量数据时,由于内部没有使用scroll模块,会由深度分页导致OOM
  方式3:
       版本: all
       使用scroll返回大量数据导致OOM
  收起阅读 »

Elastic南京meetup分享征集中

南京meetup筹备中,有意提供分享的同学请将
1. 个人简介
2. 主题简介
3. 大概内容
发送到 kenny_ye@trendmicro.com.cn
 
征稿截止日期: 2017年5月7日
 
欢迎踊跃投稿!
继续阅读 »
南京meetup筹备中,有意提供分享的同学请将
1. 个人简介
2. 主题简介
3. 大概内容
发送到 kenny_ye@trendmicro.com.cn
 
征稿截止日期: 2017年5月7日
 
欢迎踊跃投稿! 收起阅读 »

elasticsearch-query-tookit一款基于SQL查询elasticsearch编程工具包,支持SQL解析生成DSL,支持JDBC驱动,支持和Spring、MyBatis集成

`elasticsearch-query-tookit`是一款基于SQL查询elasticsearch编程工具包,支持SQL解析生成DSL,支持JDBC驱动,支持和Spring、MyBatis集成,提供Java编程接口可基于此工具包二次开发
 
只是重新造了个轮子,有兴趣的同学可以相互交流,QQ: 465360798
 
项目地址:https://github.com/gitchennan/ ... olkit
 
一、SQL解析生成DSL使用示例
SQL语法帮助手册戳这里: https://github.com/gitchennan/ ... p-doc
 
String sql = "select * from index.order where status='SUCCESS' and price > 100 order by nvl(pride, 0) asc routing by 'JD' limit 0, 20";

ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser();
//解析SQL
ElasticSqlParseResult parseResult = sql2DslParser.parse(sql);
//生成DSL(可用于rest api调用)
String dsl = parseResult.toDsl();

//toRequest方法接收一个clinet对象参数
SearchRequestBuilder searchReq = parseResult.toRequest(esClient);
//执行查询
SearchResponse response = searchReq.execute().actionGet();
生成的DSL如下:
{
"from" : 0,
"size" : 20,
"query" : {
"bool" : {
"filter" : {
"bool" : {
"must" : [ {
"term" : {
"status" : "SUCCESS"
}
}, {
"range" : {
"price" : {
"from" : 100,
"to" : null,
"include_lower" : false,
"include_upper" : true
}
}
} ]
}
}
}
},
"sort" : [ {
"pride" : {
"order" : "asc",
"missing" : 0
}
} ]
}
二、集成MyBatis、Spring
 
首先在Spring配置文件中增加如下代码
1. 指定driverClassName:org.elasticsearch.jdbc.api.ElasticDriver
2. 指定连接ES的连接串:jdbc:elastic:192.168.0.109:9300/product_cluster
3. 创建一个SqlMapClient对象,并指定sqlMapConfig.xml路径
 
<bean id="elasticDataSource" class="org.elasticsearch.jdbc.api.ElasticSingleConnectionDataSource" destroy-method="destroy">
<property name="driverClassName" value="org.elasticsearch.jdbc.api.ElasticDriver" />
<property name="url" value="jdbc:elastic:192.168.0.109:9300/product_cluster" />
</bean>

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="elasticDataSource" />
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
</bean>
sqlMapConfig.xml文件内容如下:
<sqlMapConfig>
<settings
cacheModelsEnabled="true"
lazyLoadingEnabled="true"
enhancementEnabled="true"
maxSessions="64"
maxTransactions="20"
maxRequests="128"
useStatementNamespaces="true"/>

<sqlMap resource="sqlmap/PRODUCT.xml"/>

</sqlMapConfig>
PRODUCT.xml文件中声明select sql语句
<sqlMap namespace="PRODUCT">
<select id="getProductByCodeAndMatchWord" parameterClass="java.util.Map" resultClass="java.lang.String">
SELECT *
FROM index.product
QUERY match(productName, #matchWord#) or prefix(productName, #prefixWord#, 'boost:2.0f')
WHERE productCode = #productCode#
AND advicePrice > #advicePrice#
AND $$buyers.buyerName IN ('china', 'usa')
ROUTING BY #routingVal#
</select>
</sqlMap>
编写对应DAO代码:
@Repository
public class ProductDao {
@Autowired
@Qualifier("sqlMapClient")
private SqlMapClient sqlMapClient;


public List<Product> getProductByCodeAndMatchWord(String matchWord, String productCode) throws SQLException {
Map<String, Object> paramMap = Maps.newHashMap();
paramMap.put("productCode", productCode);
paramMap.put("advicePrice", 1000);
paramMap.put("routingVal", "A");
paramMap.put("matchWord", matchWord);
paramMap.put("prefixWord", matchWord);
String responseGson = (String) sqlMapClient.queryForObject("PRODUCT.getProductByCodeAndMatchWord", paramMap);

//反序列化查询结果
JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
JdbcSearchResponse<Product> searchResponse = responseResolver.resolveSearchResponse(Product.class);

return searchResponse.getDocList();

}
}
编写测试方法
@Test
public void testProductQuery() throws Exception {
BeanFactory factory = new ClassPathXmlApplicationContext("application-context.xml");
ProductDao productDao = factory.getBean(ProductDao.class);

List<Product> productList = productDao.getProductByCodeAndMatchWord("iphone 6s", "IP_6S");
for (Product product : productList) {
System.out.println(product.getProductName());
}
}

 
 
继续阅读 »
`elasticsearch-query-tookit`是一款基于SQL查询elasticsearch编程工具包,支持SQL解析生成DSL,支持JDBC驱动,支持和Spring、MyBatis集成,提供Java编程接口可基于此工具包二次开发
 
只是重新造了个轮子,有兴趣的同学可以相互交流,QQ: 465360798
 
项目地址:https://github.com/gitchennan/ ... olkit
 
一、SQL解析生成DSL使用示例
SQL语法帮助手册戳这里: https://github.com/gitchennan/ ... p-doc
 
String sql = "select * from index.order where status='SUCCESS' and price > 100 order by nvl(pride, 0) asc routing by 'JD' limit 0, 20";

ElasticSql2DslParser sql2DslParser = new ElasticSql2DslParser();
//解析SQL
ElasticSqlParseResult parseResult = sql2DslParser.parse(sql);
//生成DSL(可用于rest api调用)
String dsl = parseResult.toDsl();

//toRequest方法接收一个clinet对象参数
SearchRequestBuilder searchReq = parseResult.toRequest(esClient);
//执行查询
SearchResponse response = searchReq.execute().actionGet();
生成的DSL如下:
{
"from" : 0,
"size" : 20,
"query" : {
"bool" : {
"filter" : {
"bool" : {
"must" : [ {
"term" : {
"status" : "SUCCESS"
}
}, {
"range" : {
"price" : {
"from" : 100,
"to" : null,
"include_lower" : false,
"include_upper" : true
}
}
} ]
}
}
}
},
"sort" : [ {
"pride" : {
"order" : "asc",
"missing" : 0
}
} ]
}
二、集成MyBatis、Spring
 
首先在Spring配置文件中增加如下代码
1. 指定driverClassName:org.elasticsearch.jdbc.api.ElasticDriver
2. 指定连接ES的连接串:jdbc:elastic:192.168.0.109:9300/product_cluster
3. 创建一个SqlMapClient对象,并指定sqlMapConfig.xml路径
 
<bean id="elasticDataSource" class="org.elasticsearch.jdbc.api.ElasticSingleConnectionDataSource" destroy-method="destroy">
<property name="driverClassName" value="org.elasticsearch.jdbc.api.ElasticDriver" />
<property name="url" value="jdbc:elastic:192.168.0.109:9300/product_cluster" />
</bean>

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="dataSource" ref="elasticDataSource" />
<property name="configLocation" value="classpath:sqlMapConfig.xml"/>
</bean>
sqlMapConfig.xml文件内容如下:
<sqlMapConfig>
<settings
cacheModelsEnabled="true"
lazyLoadingEnabled="true"
enhancementEnabled="true"
maxSessions="64"
maxTransactions="20"
maxRequests="128"
useStatementNamespaces="true"/>

<sqlMap resource="sqlmap/PRODUCT.xml"/>

</sqlMapConfig>
PRODUCT.xml文件中声明select sql语句
<sqlMap namespace="PRODUCT">
<select id="getProductByCodeAndMatchWord" parameterClass="java.util.Map" resultClass="java.lang.String">
SELECT *
FROM index.product
QUERY match(productName, #matchWord#) or prefix(productName, #prefixWord#, 'boost:2.0f')
WHERE productCode = #productCode#
AND advicePrice > #advicePrice#
AND $$buyers.buyerName IN ('china', 'usa')
ROUTING BY #routingVal#
</select>
</sqlMap>
编写对应DAO代码:
@Repository
public class ProductDao {
@Autowired
@Qualifier("sqlMapClient")
private SqlMapClient sqlMapClient;


public List<Product> getProductByCodeAndMatchWord(String matchWord, String productCode) throws SQLException {
Map<String, Object> paramMap = Maps.newHashMap();
paramMap.put("productCode", productCode);
paramMap.put("advicePrice", 1000);
paramMap.put("routingVal", "A");
paramMap.put("matchWord", matchWord);
paramMap.put("prefixWord", matchWord);
String responseGson = (String) sqlMapClient.queryForObject("PRODUCT.getProductByCodeAndMatchWord", paramMap);

//反序列化查询结果
JdbcSearchResponseResolver responseResolver = new JdbcSearchResponseResolver(responseGson);
JdbcSearchResponse<Product> searchResponse = responseResolver.resolveSearchResponse(Product.class);

return searchResponse.getDocList();

}
}
编写测试方法
@Test
public void testProductQuery() throws Exception {
BeanFactory factory = new ClassPathXmlApplicationContext("application-context.xml");
ProductDao productDao = factory.getBean(ProductDao.class);

List<Product> productList = productDao.getProductByCodeAndMatchWord("iphone 6s", "IP_6S");
for (Product product : productList) {
System.out.println(product.getProductName());
}
}

 
  收起阅读 »

写了几篇ElasticSearch入门的文章分享一下

我把自己建立一个简单的中文搜索引擎的过程写成了几篇博客。在这里和大家分享一下:
 
轻轻松松做个强大的搜索引擎01 -- 数据库安装:
https://www.zhuxichi.com/2017/ ... al01/
 
轻轻松松做个强大的搜索引擎02 -- 数据录入:
https://www.zhuxichi.com/2017/ ... al02/
 
轻轻松松做个强大的搜索引擎03 -- 全文搜索:
https://www.zhuxichi.com/2017/ ... al03/
 
轻轻松松做个强大的搜索引擎04 -- 分词:
https://www.zhuxichi.com/2017/ ... al04/
 
轻轻松松做个强大的搜索引擎05 -- 关键词高亮:
https://www.zhuxichi.com/2017/ ... al05/
 
轻轻松松做个强大的搜索引擎06 -- 搜索词建议:
https://www.zhuxichi.com/2017/ ... al06/
 
轻轻松松做个强大的搜索引擎07 -- Boosting:
https://www.zhuxichi.com/2017/ ... al07/
 
欢迎交流哈
继续阅读 »
我把自己建立一个简单的中文搜索引擎的过程写成了几篇博客。在这里和大家分享一下:
 
轻轻松松做个强大的搜索引擎01 -- 数据库安装:
https://www.zhuxichi.com/2017/ ... al01/
 
轻轻松松做个强大的搜索引擎02 -- 数据录入:
https://www.zhuxichi.com/2017/ ... al02/
 
轻轻松松做个强大的搜索引擎03 -- 全文搜索:
https://www.zhuxichi.com/2017/ ... al03/
 
轻轻松松做个强大的搜索引擎04 -- 分词:
https://www.zhuxichi.com/2017/ ... al04/
 
轻轻松松做个强大的搜索引擎05 -- 关键词高亮:
https://www.zhuxichi.com/2017/ ... al05/
 
轻轻松松做个强大的搜索引擎06 -- 搜索词建议:
https://www.zhuxichi.com/2017/ ... al06/
 
轻轻松松做个强大的搜索引擎07 -- Boosting:
https://www.zhuxichi.com/2017/ ... al07/
 
欢迎交流哈 收起阅读 »