安装好ELK后,默认的elasticsearch用的分词器为standard analyzer,所以我们的异常“org.springframework.jdbc.BadSqlGrammarException”不能通过BadSqlGrammarException搜索到。
以“one.two.three.+four”为例子,如果用standard analyzer,只有两个term,用simple将有4个term
https://discuss.elastic.co/t/dot-analyzer/3635/2
default analyzer,即standard analyzer
http://localhost:9200/twitter/_analyze?text=one.two.three.+four&pretty=1'
{
"tokens" : [ {
"token" : "one.two.three",
"start_offset" : 0,
"end_offset" : 14,
"type" : "",
"position" : 1
}, {
"token" : "four",
"start_offset" : 15,
"end_offset" : 19,
"type" : "",
"position" : 2
} ]
}
改用simple analyzer,有4个term被分出来:
http://localhost:9200/twitter/_analyze?analyzer=simple&text=one.two.three.+four&pretty=1
'
{
"tokens" : [ {
"token" : "one",
"start_offset" : 0,
"end_offset" : 3,
"type" : "word",
"position" : 1
}, {
"token" : "two",
"start_offset" : 4,
"end_offset" : 7,
"type" : "word",
"position" : 2
}, {
"token" : "three",
"start_offset" : 8,
"end_offset" : 13,
"type" : "word",
"position" : 3
}, {
"token" : "four",
"start_offset" : 15,
"end_offset" : 19,
"type" : "word",
"position" : 4
} ]
}
分词器可以为每个query指定,每个field或者每个index。refer to :https://www.elastic.co/guide/en/elasticsearch/reference/current/analyzer.html
es选择分词器的顺序为:
索引阶段
-An analyzer named default in the index settings.
-The standard analyzer.
查询阶段
-The search_analyzer defined in the field mapping.
-The analyzer defined in the field mapping.
-An analyzer named default_search in the index settings.
-An analyzer named default in the index settings.
-The standard analyzer.
我们设置logstash过来的数据对message field指定为simple analyzer:
PUT _template/logstash { "template" : "logstash-*", "mappings": { "test": { "properties": { "message": { "type": "text", "analyzer": "simple" } } } } }
创建一个名为logstash的template,它应用于所有名为logstash-*的index,为这个template建了一个名为test的mapping,该mapping下的message filed为文本类型,使用的analyze为simple。
OK,更改了名为logstash-*的index的analyzer为simple analyzer。测试一下:
1)在logstash监听的log中增加一条数据:
2)看到elasticsearch的console打出一行日志,上面这条数据已经被索引,并使用了我们定义的template logstash,以及我们的mapping test:
*关于 shards [5]/[1]:
By default, each index in Elasticsearch is allocated 5 primary shards and 1 replica which means that if you have at least two nodes in your cluster, your index will have 5 primary shards and another 5 replica shards (1 complete replica) for a total of 10 shards per index.
refer to:https://www.elastic.co/guide/en/elasticsearch/reference/current/_basic_concepts.html#getting-started-shards-and-replicas
3)测试通过“ jdbc”在message field来搜索:
GET /_search { "query": { "query_string": { "query": "jdbc", "fields": [ "message" ] } } }
可以看到搜索成功:
{ "took": 0, "timed_out": false, "_shards": { "total": 6, "successful": 6, "failed": 0 }, "hits": { "total": 1, "max_score": 1.1290016, "hits": [ { "_index": "logstash-2017.07.06", "_type": "testlogs", "_id": "AV0YmlmqLzl7sqCPLrgd", "_score": 0.28582606, "_source": { "path": "/Users/jo/lp_logs/error.log", "@timestamp": "2017-07-06T15:52:34.975Z", "@version": "1", "host": "Zhuos-MacBook-Pro.local", "message": "\torg.springframework.jdbc.BadSqlGrammarException: ### Error querying database.", "type": "testlogs" } } ] } }
在Kibana中搜索message:jdbc即可获得结果。
但是比较奇怪的现象是,必须指定message域才能查出来。而message中的一些其他term,比如“Error”就可以不指定message直接查出来。
相关推荐
ElasticSearch+IKAnalyzer整合版 解压即用。
(狂神)ElasticSearch快速入门笔记,ElasticSearch基本操作以及爬虫(Java-ES仿京东实战),包含了小狂神讲的东西,特别适合新手学习,笔记保存下来可以多看看。好记性不如烂笔头哦~,ElasticSearch,简称es,es是一个...
文件说明:本zip包含IKAnalyzer的src及elasticsearch可运行插件plugins两部分。 使用说明:修改src源码后可通过IKAnalzyerDemo、LuceneIndexAndSearchDemo测试分词及检索。将编译后jar包替换plugins中相应jar包即可...
elasticsearch elasticsearch-6.2.2 elasticsearch-6.2.2.zip 下载
ik分析插件将lucene ik analyzer(http://code.google.com/p/ik-analyzer/)集成到elasticsearch中,支持自定义字典。
elasticsearch-8.2.3 windows 版本。 Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的...
一、概述 一般来说我们开发Elasticsearch会选择...2、elasticsearch-head (方便查看ES中的索引及数据) 3、Kibana(方便开发通过rest api 调试ES,有代码提示) 4、中文分词elasticsearch-analysis-ik (ik) 1、下载ela
elasticsearch-7.17.6及对应版本IK分词 适合人群:elasticsearch初学者 Elasticsearch 是位于 Elastic Stack 核心的分布式搜索和分析引擎。Logstash 和 Beats 有助于收集、聚合和丰富您的数据并将其存储在 Elastic...
赠送jar包:elasticsearch-6.8.3.jar; 赠送原API文档:elasticsearch-6.8.3-javadoc.jar; 赠送源代码:elasticsearch-6.8.3-sources.jar; 赠送Maven依赖信息文件:elasticsearch-6.8.3.pom; 包含翻译后的API文档...
赠送jar包:elasticsearch-6.3.0.jar; 赠送原API文档:elasticsearch-6.3.0-javadoc.jar; 赠送源代码:elasticsearch-6.3.0-sources.jar; 赠送Maven依赖信息文件:elasticsearch-6.3.0.pom; 包含翻译后的API文档...
docker run --name elasticsearch7.16.3 -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 -e "discovery.type=single-node" -v /Users/xingyue/Home/xingyue/学习/工程化/es/elasticsearch.yml:/usr/share/elastic...
适用于7.17.1系列,例如Elasticsearch的7.17.12版本。 elasticsearch-analysis-ik 是一个常用的中文分词器,在 Elasticsearch 中广泛应用于中文文本的分析和搜索。下面是 elasticsearch-analysis-ik 分词器的几个...
消费kafka数据,然后批量导入到Elasticsearch,本例子使用的kafka版本0.10,es版本是6.4,使用bulk方式批量导入到es中,也可以一条一条的导入,不过比较慢。 <groupId>org.elasticsearch <artifactId>elastic...
赠送jar包:elasticsearch-6.8.3.jar; 赠送原API文档:elasticsearch-6.8.3-javadoc.jar; 赠送源代码:elasticsearch-6.8.3-sources.jar; 赠送Maven依赖信息文件:elasticsearch-6.8.3.pom; 包含翻译后的API文档...
最新版elasticsearch-analysis-ik-8.8.2.zip最新版elasticsearch-analysis-ik-8.8.2.zip最新版elasticsearch-analysis-ik-8.8.2.zip最新版elasticsearch-analysis-ik-8.8.2.zip
赠送jar包:elasticsearch-6.2.3.jar; 赠送原API文档:elasticsearch-6.2.3-javadoc.jar; 赠送源代码:elasticsearch-6.2.3-sources.jar; 赠送Maven依赖信息文件:elasticsearch-6.2.3.pom; 包含翻译后的API文档...
ElasticSearch实战 in Action(原著原版)压缩包,ElasticSearch文档,ES全文检索从入门到精通,高清PDF,是学习es和精通es必备手册,能快速达到精通ElasticSearch,一册在手,ElasticSearch无忧,开发、学习、调优...
ElasticSearch数据导出 elasticsearch单文档数据导出 支持自定义查询 导出数据Json文件
最新版windows elasticsearch-8.8.2-windows-x86_64.zip最新版windows elasticsearch-8.8.2-windows-x86_64.zip最新版windows elasticsearch-8.8.2-windows-x86_64.zip最新版windows elasticsearch-8.8.2-windows-...
ElasticSearch官网文档中文版