Q:非洲食人族的酋长吃什么?

Sql on Elasticsearch

Elasticsearchhill 发表了文章 • 9 个评论 • 8710 次浏览 • 2017-04-28 11:25 • 来自相关话题

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

bulk批量导入数据后查询的数据条数几乎都是3000或4000等这样的数据且不对

Elasticsearch匿名用户 回复了问题 • 4 人关注 • 2 个回复 • 3683 次浏览 • 2018-03-06 17:49 • 来自相关话题

困扰好久的 elk 收集自定义日志的mapping问题

Logstashjiakechong1642 回复了问题 • 2 人关注 • 2 个回复 • 8192 次浏览 • 2017-05-05 15:13 • 来自相关话题

ElasticSearch 5.x missing解决方案

Elasticsearchqweas11 回复了问题 • 3 人关注 • 2 个回复 • 5827 次浏览 • 2017-08-19 17:51 • 来自相关话题

ElasticSearch5.3.0 Java客户端运行实例?

Elasticsearchfhyes123 回复了问题 • 2 人关注 • 1 个回复 • 6315 次浏览 • 2017-04-27 16:15 • 来自相关话题

es 索引为什么远远大于服务端.log文件(195Mi vs 27M)

回复

ElasticsearchLincoln 发起了问题 • 1 人关注 • 0 个回复 • 4432 次浏览 • 2017-04-26 17:07 • 来自相关话题

过滤聚合后结果,使用javaAPI

回复

ElasticsearchTBO_ll 发起了问题 • 1 人关注 • 0 个回复 • 3487 次浏览 • 2017-04-26 16:41 • 来自相关话题

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

Logstashjiakechong1642 发表了文章 • 5 个评论 • 12934 次浏览 • 2017-04-26 16:14 • 来自相关话题

问题发生背景:

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"}
}
}
}
}



 

spark 向ES中写入数据报错

Elasticsearchshiyuan 回复了问题 • 3 人关注 • 2 个回复 • 5254 次浏览 • 2017-05-03 15:38 • 来自相关话题

elasticsearch建议词的来源和分析相关

回复

Elasticsearchllnjava 回复了问题 • 1 人关注 • 1 个回复 • 4200 次浏览 • 2017-04-26 15:07 • 来自相关话题

elasticsearch将2个field的大小比较结果作为筛选条件

Elasticsearchkennywu76 回复了问题 • 5 人关注 • 2 个回复 • 4414 次浏览 • 2017-04-27 16:59 • 来自相关话题

elasticsearch 类型关联查询方案?

回复

Elasticsearchthiefsmart 发起了问题 • 2 人关注 • 0 个回复 • 3425 次浏览 • 2017-04-26 14:44 • 来自相关话题

SUM 聚合统计值最大长度

Elasticsearchmedcl 回复了问题 • 2 人关注 • 1 个回复 • 4940 次浏览 • 2017-05-17 09:24 • 来自相关话题

elasticsearch拼音提示指定字段问题

Elasticsearchwengqiankun 回复了问题 • 4 人关注 • 2 个回复 • 4229 次浏览 • 2017-06-21 18:16 • 来自相关话题

es-jdbc为什么只支持到2.3.4,后面的版本不更新了吗

回复

Elasticsearchsuda777 发起了问题 • 1 人关注 • 0 个回复 • 4361 次浏览 • 2017-04-26 09:52 • 来自相关话题