2019独角兽企业重金招聘Python工程师标准>>>

Elasticsearch——Templates 模板 博客分类: java 搜索引擎,爬虫

刚开始的时候,每次实验都去改/etc/elasticsearch/elasticsearch.yml配置文件。事实上在template里修改settings更方便而且灵活!当然最主要的,还是调节里面的properties设定,合理的控制store和analyze了。

template设定也有多种方法。最简单的就是和存储数据一样POST上去。长期的办法,就是写成json文件放在配置路径里。其中,default配置放在/etc/elasticsearch/下,其他配置放在/etc/elasticsearch/templates/下。举例我现在的一个templates/template-logstash.json内容如下:

Java代码  
  1. {
  2. "template-logstash" : {
  3. "template" : "logstash*",
  4. "settings" : {
  5. "index.number_of_shards" : 5,
  6. "number_of_replicas" : 1,
  7. "index" : {
  8. "store" : {
  9. "compress" : {
  10. "stored" : true,
  11. "tv": true
  12. }
  13. }
  14. }
  15. },
  16. "mappings" : {
  17. "_default_" : {
  18. "properties" : {
  19. "dynamic" : "true",
  20. },
  21. },
  22. "loadbalancer" : {
  23. "_source" : {
  24. "compress" : true,
  25. },
  26. "_ttl" : {
  27. "enabled" : true,
  28. "default" : "10d"
  29. },
  30. "_all" : {
  31. "enabled" : false
  32. },
  33. "properties" : {
  34. "@fields" : {
  35. "dynamic" : "true",
  36. "properties" : {
  37. "client" : {
  38. "type" : "string",
  39. "index" : "not_analyzed"
  40. },
  41. "domain" : {
  42. "type" : "string",
  43. "index" : "not_analyzed"
  44. },
  45. "oh" : {
  46. "type" : "string",
  47. "index" : "not_analyzed"
  48. },
  49. "responsetime" : {
  50. "type" : "double",
  51. },
  52. "size" : {
  53. "type" : "long",
  54. "index" : "not_analyzed"
  55. },
  56. "status" : {
  57. "type" : "string",
  58. "index" : "not_analyzed"
  59. },
  60. "upstreamtime" : {
  61. "type" : "double",
  62. },
  63. "url" : {
  64. "type" : "string",
  65. "index" : "not_analyzed"
  66. }
  67. }
  68. },
  69. "@source" : {
  70. "type" : "string",
  71. "index" : "not_analyzed"
  72. },
  73. "@timestamp" : {
  74. "type" : "date",
  75. "format" : "dateOptionalTime"
  76. },
  77. "@type" : {
  78. "type" : "string",
  79. "index" : "not_analyzed",
  80. "store" : "no"
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }

注意: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”开头的索引。 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

{
"test" : {
"template" : "test*" ,
"settings" : {
"index.number_of_shards" : 5 ,
"number_of_replicas" : 1
} ,
"mappings" : {
"_default_" : {
"_source" : {
"enabled" : false
}
} ,
"news" : {
"_source" : {
"enabled" : true
} ,
"_all" : {
"enabled" : false
} ,
"properties" : {
"site_id" : {
"type" : "integer" ,
"index" : "not_analyzed"
} ,
"title" : {
"type" : "string" ,
"index" : "analyzed" ,
"analyzer" : "whitespace"
} ,
"media_type" : {
"type" : "short" ,
"index" : "not_analyzed"
}
}
}
}
}
}

3. _source字段

_source字段是自动生成的,以JSON格式存储索引文件。_source字段没有建索引,所以不可搜索。当执行“get”或者“search”操作时,默认会返回_source字段。

_source字段消耗性能,所以可以屏蔽(disable)掉。例如:

1
2
3
4
5

{
"tweet" : {
"_source" : { "enabled" : false }
}
}

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

转载于:https://my.oschina.net/xiaominmin/blog/1597110

Elasticsearch——Templates 模板相关推荐

  1. Python测试开发django5.templates模板变量传参

    上一篇,我们学习了Python测试开发django4.templates模板配置 templates模板中html文件是一个静态页面,写四的,如果有时我们想动态的传入一些不同的参数,想实现在一个固定的 ...

  2. Python测试开发django4.templates模板配置

    [上一篇]我们讲了Python测试开发django3.视图和URL配置 今天详细介绍下 Django 模板的应用,模板是一个文本,用于分离文档的表现形式和内容. 我们已经知道创建项目用django-a ...

  3. python后台架构Django教程——templates模板

    全栈工程师开发手册 (作者:栾鹏) 本文衔接至python后台架构Django开发全解. 有其他问题请先阅读:http://blog.csdn.net/luanpeng825485697/articl ...

  4. Django学习系列之五:Django 的模板的render替换render_to_string用法及templates模板查找路径顺序

    Django学习系列之五:Django 的模板的render替换render_to_string用法及templates模板查找路径顺序 1.Django 的模板的render替换render_to_ ...

  5. django html过滤,django templates模板过滤器过滤掉字符串含有的html标签

    django templates模板过滤器过滤掉字符串含有的html标签 在template用法:{{ myvar|striptags }} 如果myvar的字符串是"吾爱孟夫子,风流天下闻 ...

  6. 【Elasticsearch】Elasticsearch 动态模板(Dynamic templates)

    1.概述 动态映射请参考: [Elasticsearch]Elasticsearch 7 : 动态映射 dynamic 本博客摘抄自:Elastic Stack 实战手册(早鸟版).pdf 原文可看, ...

  7. django使用templates模板

    Django中Settings中Templates的路径设置 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 ## mysite/mysite/settings.p ...

  8. Django之templates模板

    模板的使用 1.如何使用模板 在manage.py的同级文件夹中创建templates 在setting.py的文件中把第58行'DIRS': [ ],改成'DIRS': [os.path.join( ...

  9. Elasticsearch 索引模板

    概述 记录自己在工作中将生产的数据按月保存在ES中(通过logstash采集kafka数据到ES),由于生产环境数据量比较庞大(一天的日志量大概在2500万条左右),为了后期减轻服务器压力,方便我们维 ...

最新文章

  1. 遇见BUG(2)去掉你的增量编译使能!
  2. 平正真诚——记红帆公司2011年秋季旅游·衡山
  3. 【推荐】用这些 App 提高你的睡眠质量
  4. vjue 点击发送邮件如何处理
  5. [转贴]Silverlight Socket 实现收发信息
  6. 多分类问题的另一种处理策略——softmax回归
  7. NIKKEI Programming Contest 2019 翻车记
  8. CentOS7.3上部署安装Oracle12c
  9. min-width_min-height_max-width_max-height 设置元素最小或最大长度
  10. Python常用的一些库(仅供参考)
  11. 夏普M3508U复印机无法打印的解决方法
  12. ftp访问命令 linux,linux访问ftp服务器命令
  13. excel如何设置保留两位小数
  14. 计算机电缆检测报告,计算机用屏蔽双绞线DJYPVP-2*2*1.0mm²
  15. MyEclipse10破解 运行run.bat闪退 亲自试验
  16. linux目录显示蓝色,centos系统创建文件夹目录显示颜色
  17. led大屏按实际尺寸设计画面_led显示屏尺寸大小的计算方式
  18. 个人支付微信支付宝接口
  19. 从原理层面掌握@RequestAttribute、@SessionAttribute的使用【享学Spring MVC】
  20. 能够证明“3=0”吗?

热门文章

  1. lodop打印技巧与注意事项
  2. REDHAT6.4桌面环境添加快捷建打开命令行终端
  3. Kickstart的配置文件anaconda-ks.cfg解析
  4. 如何防止apk程序被反编译
  5. 跨浏览器开发经验总结(三)
  6. 域控制器建立以及一般配置
  7. 掌握ConstraintLayout(十)按比例设置视图大小
  8. spark 入门及集群环境搭建
  9. 用工具进行CAD转换图片的过程
  10. 锋利的jQuery-4--动画方法总结简表