刚开始的时候,每次实验都去改/etc/elasticsearch/elasticsearch.yml配置文件。事实上在template里修改settings更方便而且灵活!当然最主要的,还是调节里面的properties设定,合理的控制store和analyze了。
template设定也有多种方法。最简单的就是和存储数据一样POST上去。长期的办法,就是写成json文件放在配置路径里。其中,default配置放在/etc/elasticsearch/下,其他配置放在/etc/elasticsearch/templates/下。举例我现在的一个templates/template-logstash.json内容如下:
- {
- "template-logstash" : {
- "template" : "logstash*",
- "settings" : {
- "index.number_of_shards" : 5,
- "number_of_replicas" : 1,
- "index" : {
- "store" : {
- "compress" : {
- "stored" : true,
- "tv": true
- }
- }
- }
- },
- "mappings" : {
- "_default_" : {
- "properties" : {
- "dynamic" : "true",
- },
- },
- "loadbalancer" : {
- "_source" : {
- "compress" : true,
- },
- "_ttl" : {
- "enabled" : true,
- "default" : "10d"
- },
- "_all" : {
- "enabled" : false
- },
- "properties" : {
- "@fields" : {
- "dynamic" : "true",
- "properties" : {
- "client" : {
- "type" : "string",
- "index" : "not_analyzed"
- },
- "domain" : {
- "type" : "string",
- "index" : "not_analyzed"
- },
- "oh" : {
- "type" : "string",
- "index" : "not_analyzed"
- },
- "responsetime" : {
- "type" : "double",
- },
- "size" : {
- "type" : "long",
- "index" : "not_analyzed"
- },
- "status" : {
- "type" : "string",
- "index" : "not_analyzed"
- },
- "upstreamtime" : {
- "type" : "double",
- },
- "url" : {
- "type" : "string",
- "index" : "not_analyzed"
- }
- }
- },
- "@source" : {
- "type" : "string",
- "index" : "not_analyzed"
- },
- "@timestamp" : {
- "type" : "date",
- "format" : "dateOptionalTime"
- },
- "@type" : {
- "type" : "string",
- "index" : "not_analyzed",
- "store" : "no"
- }
- }
- }
- }
- }
- }
注意:POST 发送的 json 内容比存储的 json 文件内容要少最外层的名字,因为名字是在 url 里体现的。
Elasticsearch可以预先定义索引模板,当创建新索引时,可以自动匹配模板。模板包括settings和mappings,以及一个匹配索引的正则。
1. 使用curl方式操作templates
详细查阅:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-templates.html
2. 配置文件方式
在config目录下创建目录templates,所有模板文件都放在config/templates目录下。
例如:test.json,模板匹配所有以“test”开头的索引。
3. _source字段
_source字段是自动生成的,以JSON格式存储索引文件。_source字段没有建索引,所以不可搜索。当执行“get”或者“search”操作时,默认会返回_source字段。
_source字段消耗性能,所以可以屏蔽(disable)掉。例如:
enabale:false的情况下,默认检索只返回ID。
如果觉得enabale:true时,索引的膨涨率比较大的情况下可以通过下面一些辅助设置进行优化:
Compress:是否进行压缩,建议一般情况下将其设为true
“includes” : ["author", "name"],
“excludes” : ["sex"]
上面的includes和 excludes主要是针对默认情况下面_source一般是保存全部Bulk过去的数据,我们可以通过include,excludes在字段级别上做出一些限索。
详细请查阅:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-source-field.html#mapping-source-field
4. _all字段
主要指的是All Field字段,我们可以将一个或都多个包含进去,在进行检索时无需指定字段的情况下检索多个字段。前提是你得开启All Field字段 “_all” : {“enabled” : true}。好处是你可以在_all里搜索那些你不在乎在哪个字段找到的东西。另一面是在创建索引和增大索引大小的时候会使用额外更多的CPU。所以如果你不用这个特性的话,关掉它。即使你用,最好也考虑一下定义清楚限定哪些字段包含进_all里。
http://blog.csdn.net/july_2/article/details/27551739
http://www.cnblogs.com/huangfox/p/3544883.html
相关推荐
这是一个搜索引擎的开发包固件,通过它你可以和qython对接
ElasticSearch Grafana监控模板
(狂神)ElasticSearch快速入门笔记,ElasticSearch基本操作以及爬虫(Java-ES仿京东实战),包含了小狂神讲的东西,特别适合新手学习,笔记保存下来可以多看看。好记性不如烂笔头哦~,ElasticSearch,简称es,es是一个...
elasticsearch elasticsearch-6.2.2 elasticsearch-6.2.2.zip 下载
elasticsearch中文文档——基于7.11.zip
elasticsearch-7.17.6及对应版本IK分词 适合人群:elasticsearch初学者 Elasticsearch 是位于 Elastic Stack 核心的分布式搜索和分析引擎。Logstash 和 Beats 有助于收集、聚合和丰富您的数据并将其存储在 Elastic...
分享一套完整版视频课程——分布式搜索引擎Elasticsearch开发实战基础篇 (ElasticSearch、ELK、搜索引擎、Lucene),本教程旨在带领大家进入搜索引擎领域,从无到有,深入浅出的讲解了什么是搜索引擎,搜索引擎的...
一、概述 一般来说我们开发Elasticsearch会选择...2、elasticsearch-head (方便查看ES中的索引及数据) 3、Kibana(方便开发通过rest api 调试ES,有代码提示) 4、中文分词elasticsearch-analysis-ik (ik) 1、下载ela
elasticsearch-8.2.3 windows 版本。 Elasticsearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java语言开发的,并作为Apache许可条款下的...
赠送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文档...
适用于7.17.1系列,例如Elasticsearch的7.17.12版本。 elasticsearch-analysis-ik 是一个常用的中文分词器,在 Elasticsearch 中广泛应用于中文文本的分析和搜索。下面是 elasticsearch-analysis-ik 分词器的几个...
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...
赠送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实战 in Action(原著原版)压缩包,ElasticSearch文档,ES全文检索从入门到精通,高清PDF,是学习es和精通es必备手册,能快速达到精通ElasticSearch,一册在手,ElasticSearch无忧,开发、学习、调优...
1、进入到Elasticsearch的安装路径下,本文中以该路径为例子:/ultra/ES/elasticsearch-2.3.4。先安装license,执行以下命令: ./bin/plugin install license 2、再安装shield,执行以下命令: ./bin/plugin ...
ElasticSearch数据导出 elasticsearch单文档数据导出 支持自定义查询 导出数据Json文件
elasticsearch操作模板Demo
ElasticSearch Java API 中文文档 ElasticSearch Java API 中文文档
ElasticSearch官网文档中文版
ElasticSearch是一个基于Lucene的搜索服务器。它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口。Elasticsearch是用Java开发的,并作为Apache许可条款下的开放源码发布,是当前流行的企业级搜索...