elk权限控制_elasticsearch技术解析与实战(六) 告警、监控和权限管理、ELK

本文详细介绍了Elasticsearch的告警插件Watcher的安装、配置及使用,包括触发器设置、输入源、条件判断、转换和动作。此外,还探讨了权限管理插件Shield的安装、用户认证、角色管理和节点认证策略,以及如何在Elasticsearch 5.0中应对新特性和改进。
摘要由CSDN通过智能技术生成

告警、监控和权限管理

插件Wacher、Marvel、Shield可以对es进行告警监控、认证权限管理,但都是收费的

告警

Watcher是进行告警和通知的插件,原理是在es中执行查询,满足条件后,产生告警

安装

1、安装Watcher插件

./plugin install license

#https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/license/2.4.5/license-2.4.5.zip ->plugins/license

./plugin install watcher

#https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/watcher/2.4.5/watcher-2.4.5.zip ->plugins/watcher

#安装Watcher需要额外的权限:getClassLoader、setContextClassLoader、setFactory

2、若es中设置了禁止自动创建索引,需要在配置文件中添加action.auto_create_index:.watches,.triggered_watches,.watcher-history*

3、重启es

systemctl restart elasticsearch

4、验证安装

GET /_watcher/stats?pretty

结构

1、Trigger

告警触发器,定义开始执行的时间点。创建一个触发器时,将这个触发器注册到一个合适的触发器引擎中。所有触发器都是基于时间的

触发器使用系统时钟来确定当前时间,所以需要同步所有节点的时钟。触发器的类型有:hourly、daily、weekly、monthly、yearly、cron、interval

1)hourly

每小时执行一次,可以设置具体的分钟,默认为0分钟

#在每小时的30分执行

{..."trigger":{"schedule":{"hourly":{"minute":30}}}...}

#在小时时刻中设置多个分钟

{.."trigger":{"schedule":{"hourly":{"minute":[0,15,30,45]}}}...}

2)daily

每天某一特定时间执行,可以配置具体时间,默认0点

{..."trigger":{"schedule":{"daily":{"at":"17:00}}}...}

{..."trigger":{"schedule":{"daily":{"at":["midnight","noon","17:00]}}}...}

#midnight、noon是保留字,表示00:00和12:00

3)weekly

可以指定一周的名称、缩写或数字(星期日是一周的第一天)

sunday,monday,tuesday,wednesday,friday,saturday,sunday

sun,mon,tue,wed,thu,fri,sat ->1,2,3,4,5,6,7

{..."trigger":{"schedule":{"weekly":{"on":"friday","at":"17:00"}}}...}

可以设置多个时间点

{..."trigger":{"schedule":{"weekly":[{"on":"tuesday","at":"noon"},{"on":"friday","at":"17:00"}]}}...}

{..."trigger":{"schedule":{"weekly":{"on":["tuesday","friday"],"at":["noon","17:00"]}}}...}

4)monthly

{..."trigger":{"schedule":{"monthly":{"on":10,"at":"noon}}}...}

可以设置多个时间点

{..."trigger":{"schedule":{"monthly":[{"on":10,"at":"noon"},{"on":20,"at":"17:00"}]}}...}

{..."trigger":{"schedule":{"monthly":{"on":[10,20],"at":["midnight","noon"]}}}...}

5)yearly

可以指定月的名称、缩写或数字

january,february,march,april,may,june,july,august,september,october,november,december

jan,feb,mar,apr,may,jun,jul,aug,sep,oct,nov,dec -> 1...12

{..."trigger":{"schedule":{"yearly":{"in":"january","on",10,"at":"noon"}}}...}

可以设置多个时间点

{...trigger":{"schedule":{"yearly":[{"in":"january","on":10,"at":"noon"},{"in":"july","on":20,"at":"17:00"}]}}...}

{...trigger":{"schedule":{"yearly":{"in":["jan","dec"],"on":[10,20],"at":["midnight","noon"]}}}...}

6)cron

*,任意值;

?,日期和周会有相互影响,所以不能用*而要用?,代表任意值

-,范围

/,每,5/20表示,5分触发一次,然后每20分触发一次,即5,25,45

,,枚举

L,表示最后,5L表示最后一个星期四

W,工作日,周一至周五,系统在离指定日期最近的有效工作日触发,5W,若5日是周六,则周五触发;若5日是周日,则周一触发

LW可以连用,表示某月最后一个工作日,即最后一个星期五

#,用于确定每个月的第几个星期几,4#2表示某月第二个星期三

{..."trigger":{"schedule"{"cron":"0 0 12 * * ?"}}...} 每天中午12点执行

7)interval系统内置表达式

系统内置表达式可设置seconds、minutes、hours、days、weeks

Xs,每多少秒执行一次,30s,每30s执行一次

Xm,Xh,Xd,Xw

{..."trigger":{"schedule":{"interval":"5m"}}...}

2、inputs

输入将静态数据加载到告警执行上下文中作为判断的内容,支持四种输入源:simple、search、http、chain

1)simple input简单输入

将静态内容加载到告警执行上下文中,可以定义字符串、数值、或一个对象作为输入源

#提醒电子邮件

{"trigger":{"schedule":{"daily":{"at":"noon"}}},"input":{"simple":{"name":"John"}},"actions":{"reminder_email":{"email":{"to":"to@host.domain","subject":"Reminder","body":"Dear {{ctx.payload.name}},by the time you read this,i will be gone"}}}}

2)search input搜索输入

将搜索结果作为输入加载到告警执行上下文中作为判断内容。conditions、transforms、actions都可以通过结果属性访问搜索中的内容

ctx.payload.hits 表示搜索的所有内容

ctx.payload.hits.total 表示搜索的结果条数

ctx.payload.hits.hits.2 搜索结果的第三条数据

#搜索所有日志作为输入

"input":{"search":{"request":{"indices":["logs"],"types":["event"],"body":{"query":{"match_all":{}}}}}}

#通过模板搜索的日志作为输入

{"input":{"search":{"request":{"indices":["logs"],"template":{"id":"my_template","params":{"value":23}}}}}}

3)HTTP input HTTP协议输入

通过HTTP请求es得到的返回结果作为输入加载到告警执行上下文中作为判断的内容

"input":{"http":{"request":{"host":"example.com","port":9200,"path":"/idx/_search"}}}

#通过DSL语言进行查询

"input":{"http":{"request":{"host":"host.domain","port":9200,"path":"/idx/_search","body":"{\"query\":{\"category\":\"event\"}}}"}}}

#通过模板进行查询

"input":{"http":{"request":{"host":"host.domian","port":9200,"path":"/{{ctx.watch_id}}/_search","body":"{\"query\":{\"range\":{\"@timestamp\":{\"from\":\"{{ctx.trigger.triggered_time}}||-5m\",\"to\":\"{{ctx.trigger.triggered_time}}\"}}}}"}}}

#通过调用es API进行查询

"input":{"http":{"request":{"host":"host.domain","port":"9200","path":"/_cluster/stats","params":{"human":"true"}}}}

4)chain input链式输入

一次把多个输入加载到告警执行上下文中作为判断的内容

基于来自多个源的数据执行操作时,链输入是有用的。可以使一个输入收集的数据是从另一个源加载数据

{"input":{"chain":{"inputs":[{"first":{"simple":{"path":"/_search"}}},{"second":{"http":{"request":{"host":"localhost","port":9200,"path":"{{ctx.payload.first.path}}"}}}}]}}}

3、condition

当一个告警被触发时,condition决定是否执行下一步的动作。支持四种类型:always、never、script、compare

1)always 始终执行

"condition":{"always":{}}

2)never 永远不执行

PUT _watcher/watch/my-watch {..."condition":{"never":{}}...}

3)script 用脚本作为判断的条件,默认groovy

"condition":{"script":"return true"}

可以使用文件脚本源

"condition":{"script":{"file":"my_script","lang":"javascript","params":{"result":true}}}

4)compare 将执行上下文模型中的值与给写的值进行比较

#查询结果条数大于等于5时满足条件

{..."condition":{"compare":{"ctx.payload.hits.total":{"gte":5}}...}

eq,not_eq,gt,gte,lt,lte

{..."condition":{"compare":{"ctx.payload.aggregations.status.buckets.error.doc_count":{"not_eq":"{{ctx.payload.aggregations.handled.buckets.true.doc_count}}"}}...}

4、transform

可选项,在输入到执行动作过程中的数据处理,包括全局转换和局部转换

转换支持搜索、脚本和链转换,分别用search、script、chain表示

search转换是搜索的转换,用返回的搜索结果替换告警上下文中的内容

{"transform":{"search":{"request":{"indices":["logstash-*"],"body":{"size":0,"query":{"match":{"priority":"error"}}}}}}}

script转换是在集群上执行脚本的转换,用返回的脚本执行结果替换告警执行上下文中的内容

{..."transform":{"script":"return[time:ctx.trigger.scheduled_time]"}...}

chain转换可以一次把多个转换加载到转换中

"transform":{"chain":[{"search":{"indices":["logstash-*"],"body":{"size":0,"query":{"match":{"priority":"error"}}}}},{"script":"return [error_count:ctx.payload.hits.total]"}]}

5、action

当满足告警条件时会发生的动作。可以是邮件、HipChat、Slack等

PUT http://127.0.0.1:9200/_watch/watch/log_event_watch

{"metadata":{"color":"red"},

"trigger":{"schedule":{"interval":"5m"}},

"input":{"search":{"request":{"indices":"log-events","body":{"size":0,"query":{"match":{"status":"error"}}}}}},

"condition":{"script":"return ctx.payload.hits.total > 5"},

"actions":{"email_administrator":{"throttle_period":"15m","email":{"to":"sys.admin@host.domain","subject":"Encountered {{ctx.payload.hits.tatal}} errors","body":"Too many error in the system, see attached data","attachments":{"attached_data":{"data":{"format":"json"}}},"priority":"high"}}}}

示例

#寻找错误事件的一个告警定义

PUT http://127.0.0.1:9200/_watcher/watch/log_event_watch

{"metadata":{"color":"red"},  #元数据,可将可选的静态元数据附加到告警上

"trigger":{"schedule":{"interval":"5m"}}, #触发,每5分钟执行一次

"input":{"search":{"request":{"indices":"log-events","body":{"size":0,"query":{"match":{"status":"error"}}}}}}, #输入,搜索错误事件,并将响应加载到告警内容中

"condition":{"script":"return ctx.payload.hits.tatal > 5"}, #条件,是否超过5个错误事件

"transform":{"search":{"request":{"indices":"log-events","body":{"query":{"match":{"status":error"}}}}}}, #转换,若满足告警条件,所有动作都访问这个转换

"actions":{"my_webhook":{"webhook":{"method":"POST","host":"mylisteninghost","port":9200,"path":"/{{watch_id}}","body":"Encountered {{ctx.payload.hits.total}} errors"}},

"email_administrator":{"email":{"to":"sys.admin@host.domain","subject":"Encounted {{ctx.payload.hits.total}} errors","body":"Too many error in the system, see attached data","attachment":{"attatched_data":{"data":{"format":"json"}}},"priority":"hith"}}}} #两个动作#检查集群健康状态的告警定义

PUT http://127.0.0.1:9200/_watcher/watch/cluster_health_watch

{"trigger":{"schedule":{"interval":"10s"}},"input":{"http":{"request":{"host":"127.0.0.1","port":9200,"path":"/_cluster/health"}}},"condition":{"compare":{"ctx.payload.status":{"eq":"red"}}},"actions":{"send_email":{"email":{"to":"admin@domain","subject":"Cluster Status Warning","body":"Cluster status is RED"}}}}

告警输出配置

告警可以输出到email、webhook、logging、hipchat、slack、pagerduty

1、email

在elasticsearch.yml中配置邮件帐户并重启es

2、webhook

用于提交web数据,不需要单独配置,只需在actions中配置

"actions":{"my_webhook":{"transform":{...},"throttle_period":"5m","webhook":{"method":"POST","host":"mylisteningserver","port":"9200,"path":":/{{ctx.watch_id}}","body":"{{ctx.watch_id}}:{{ctx.payload.hits.total}}"}}}3、logging

记录日志到es中,不需要单独配置,只需在actions中配置

"actions":{"log":{"transform":{...},"logging":{"text":"executed at {{ctx.execution_time}}"}}}4、hipchat、slack、pagerduty

在国内很少用

告警管理

1、列出告警

搜索索引.watches列出所有告警的配置

GET http://127.0.0.1:9200/.watches/_search

{"fields":[],"query":{"match_all":{}}}2、删除告警

DELETE http://127.0.0.1/_watcher/watch/cluster_health_watch

监控

监控主要分为六个层面:集群层、节点层、索引层、分片层、事件层、Sense

安装

Marvel有两个组件,一个是代理,安装在es集群中;一个是Kibana插件

#安装Marvel插件

./plugin install license

./plugin install marvel-agent

#https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/marvel-agent/2.4.5/marvel-agent-2.4.5.zip

#需要权限setFactory、setHostnameVerifier

systemctl restart elasticsearch#安装Kibana的Marvel插件

./kibana plugin --install elasticsearch/marvel/latest

#https://download.elastic.co/elasticsearch/marvel/marvel-latest.tar.gz

systemctl restart kibana

配置

1、监控参数配置

可以在每个节点的elasticsearch.yml中配置marvel参数

marvel.agent.cluster.state.timeout:收集集群状态的超时时间,默认10秒

marvel.agent.cluster.state.stats.timeout:收集集群统计的超时时间,默认10秒

marvel.agent.indices:控制哪些索引数据被收集,默认所有索引,test1,test2,testd* +test*,-test3

marvel.agent.index.stats.timeout:收集索引统计的超时,默认10秒

marvel.agent.indices.stats.timeout:收集总索引统计超时时间,默认10秒

marvel.agent.exporters:配置代理监测数据。默认,代理安装在本地的集群上,它监控数据,使用HTTP协议将数据发送到一个单独的监控集群上

marvel.agent.index.recovery.active_only:是否收集所有的恢复数据,默认false

marvel.agent.index.recovery.timeout:收集恢复数据的超时时间,默认10秒

marvel.agent.interval:收集数据样本的频率,默认10秒,-1表示禁用数据

marvel.history.duration:监控创建的索引被自动删除的保留时间,默认7天,-1表示禁用自动删除2、监控索引配置

存储从集群中收集的数据

默认模板 GET /_template/.marvel-es-1 数据模板/_template/.marvel-es-data-1

默认仅一个分片,没有副本。可以覆盖默认设置

PUT /_template/custom_marvel {"template":".marvel*","order":1,"settings":{"number_of_shards":5,"number_of_replicas":2}}3、kibana配置相关

kibana.yml中可以设置marvel监控参数,通常默认值就可以很好工作

marvel.max_bucket_size:桶数量,默认10000

marvel.min_interval_seconds:时间桶能表示的最小秒数,默认10秒

marvel.node_resolver:被认为是唯一节点的标志

marvel.report_stats:是否将集群统计数据发送到Elastic公司,默认为true4、tribe部落节点监控配置

若通过部落节点连接到一个集群,需要在部落节点以及集群中的节点上安装监控代理来监控集群。若集群上设置了权限,还需要在部落节点上安装和配置权限

权限管理

Shield

#安装shield

./plugin install license

./plugin install shield

#https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/shield/2.4.5/shield-2.4.5.zip

#需要权限setFactory

systemctl restart elasticsearch

#添加管理员帐号

bin/shield/esusers useradd es_admin -r admin  #注意用户名是es_admin,执行后设置密码

配置文件位于config/shield

logging.yml

role_mapping.yml,LDAP映射

roles.yml,定义用户角色

users,保存用户名和密码

users_roles,保存用户角色

工作原理

Shield安装后,会拦截所有API请求,然后对请求进行认证和授权校验。插件提供SSL安全协议、审计日志记录等功能

1、用户认证

可以基于数据库、本地文件、LDAP、AD或KPI记录用户数据2、授权

资源,集群、索引、别名等

权限,对资源的操作

许可,对应安全资源的一个或多个权限,2种许可:集群、索引

角色,权限的集合

用户,3、节点认证和信道加密

可以使用SSL/TLS,启用时,节点相互交换验证证书,建立节点间的信任,验证未经身份验证的节点加入集群,通过验证后,内部通信是加密的4、IP过滤

可设置白名单或黑名单,可设置IP或网段5、审计

日志记录,包含登录、授权、拒绝访问等

用户认证

用户认证方式

Native,内置本地认证;File,内置基于文件的认证;LDAP,目录协议;AD,活动目录服务;PKI,X.509证书

支持多种认证方式,按顺序进行认证,在elasticsearch.yml中配置

匿名用户访问

认证过程分为两个阶段:令牌提取和用户认证。默认匿名请求被拒绝,可以通过配置启用,elasticsearch.yml

本地认证默认内置,不配置也可以

可以通过Users API完成本地认证用户的管理

#新增用户ironman

POST /_shield/user/ironman {"password":"admin888","roles":["admin","power_user"],"full_name":"Tony John","email":"tony@example.com","metadata":{"intelligence":7}}

##用户密码和角色为必填项,其他为可选

#查询本地用户

GET /_shield/user

#删除用户

DELETE /_shield/user/ironman

LDAP认证

需要配置LDAP域和指定LDAP角色的角色映射。与LDAP的通信必须使用SSL/TLS加密。

用户组所属的角色定义用户的权限

SSL/TLS加密配置方法:

1)生成证书

cd CONFIG_DIR/shield

keytool -importcert -keystore node01.jks -file cacert.pem -alias ldap_ca

2)配置elasticsearch.yml

shield.ssl.keystore.path: /home/es/config/shield/node01.jks

shield.ssl.keystore.password: myPass

shield.ssl.keystore.key_password: myKeyPass

3)配置LDAP协议的URL和端口,如url:ldaps://ldap.example.com:636

4)重启es

AD认证

需要配置AD域和指定的AD角色在角色映射文件中。和AD角色通信必须用SSL/TLS。

PKI认证

要求客户提供X.509证书

基于文件的授权

内置方式。通过esusers控制台命令增加和删除用户,分配用户角色,管理用户和密码

#增加用户

esusers useradd

#增加用户同时设置密码

esusers useradd -p

#增加用户同时设置角色

esusers useradd -r

#查询用户

esusers list

#管理密码

esusers passwd -p

#分配角色,-a增加角色,-r删除角色

esusers roles -a -r

#删除用户

esusers userdel

角色管理

Shield提供基于角色的访问控制,默认情况下,所有操作都受限。只有给用户分配角色后,用户才可以执行授权内的操作

1、增加角色

POST /_shield/role/my_admin_role {"cluster":["all"],"indices":[{"names":["index1","index2"],"privileges":["all"],"fields":["title","body"],"query":"{\"match\":{\"title\":\"foo\"}}"}],"run_as":["other_user"]}

2、查看角色

GET /_shield/role3、删除角色

DELETE /_shield/role/my_admin_role

综合示例(略)

ELK应用

Logstash

插件管理

#列出现有插件

./logstash-plugin list

./logstash-plugin list --verbose  #可以显示插件版本号

./logstash-plugin list --group output

#增加插件

./logstash-plugin install logstash-output-kafka

#更新插件

./logstash-plugin update

./logstash-plugin update logstash-output-kafka

#移除插件

./logstash-plugin uninstall logstash-output-kafka

Elasticsearch 5.0的特性与改进

5.0.0版本时间2016.10.27 2.4->5.0

elasticsearch 6.3 启动要求用户不能为root,且虚拟内存、文件描述符、最大线程数有要求,需要这样操作:

sysctl -w vm.max_map_count=262144   #临时修改

vi /etc/security/limits.conf  #生新需重新登录

dong hard nofile 65536

dong soft nofile 65536

dong hard nproc 4096

dong soft nproc 4096

ERROR: [3] bootstrap checks failed

[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]

[2]: max number of threads [3886] for user [dong] is too low, increase to at least [4096]

[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

新特性

索引性能提升、新增内置脚本Painless、新增几种数据结构、增加接口、java REST客户端

索引性能:提高25%~80%效率

数据转换节点Ingest Nodes,不依赖于Logstash实现常用的过滤能力,如grok、split、convert、date等。可以在任何节点开启转换功能或建立单独的转换节点。默认开启转换能力,要关闭,需要在配置文件中添加:node.ingest:false

#定义管道,设置foo的值始终为bar

PUT /_ingest/pipeline/my-peline-id {"description":"describe pipeline","processors":[{"set":{"field":"foo","value":"bar"}}]}

#使用管道

PUT /secisland/secilog/my-id?pipeline=my-peline-id {"foo":"text"}

新的脚本引擎Painless,基于安全和性能,Painless使用白名单限制函数与字段的访问,只做数据的操作,更加轻量级,速度要快好几倍,支持Java静态类型,语法和Groove类似,支持Java和lambda表达式

新的数据结构,集成Lucene 6,对数字类型和地理类型增加新的点数据结构,K-Ds树,它改变了数字类型的索引和搜索,增加35%查询速度、71%索引速度、减少66%磁盘空间、减少85%内存使用。新增加的IP字段支持IPv4和IPv6。地理点查询性能增加一倍

友好性接口变化:

索引:

增加Shrink接口,可以收缩分片数。Rollover接口,对日志类数据按天分割,不需要用logstash-[YYYY-MM-DD]的索引模板方式

PUT /logs-000001

{"aliases":{"logs_write":{}}}

POST logs_write/_rollover

{"conditions":{"max_age":"7d","max_docs":1000}}

先创建logs-000001索引,别名为logs_write,然后创建rollover规则,文档超过1000或保存天数超过7天,则会自动切换到logs-000002

新增Depreated logging,将标志为废弃的命令记录到日志中

新增Cluster allocation explain接口,查询分片不能分配的原因

弹性:

索引数据路径采用UUID,增加新的内存控制器,正常情况下内存不足的情况基本不会发生

索引映射的变化

String类型

Text/Keyword替换String

"test":{"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}}

数字类型

数字采用全新数据结构BKD tree,数字类型将不参与索引评分,要评分可同时映射数字类型和keyword类型,如

PUT /secisland {"mappings":{"my_type":{"properties":{"my_number":{"type":"long","fields":{"keyword":{"type":"keyword"}}}}}}}

geo_point字段

该字段也使用BKE tree结构,从根本上进行多维空间数据支持,将不再支持geohash、geohash_prefix、geohash_precision、lat_lon

_timestamp和_ttl字段

元字段_timestamp和_ttl将不再支持,对_timestamp可以在文档中添加日期字段代替或者用ingest pipline,如

PUT /_ingest/pipeline/timestamp {"description":"Adds a timpstamp field at the current time","processors":[{"set":{"field":"timestamp","value":"{{_ingest.timestamp}}"}}]}

PUT /newindex/type/1?pipeline=timestamp {"example":"data"}

对于_ttl可以用time-based索引或者在一个时间戳字段范围查询_delete-by-query来替换

POST /index/type/_delete_by_query {"query":{"range":{"timestamp":{"lt":"2016-05-01"}}}}

索引属性

所有在用的字段类型,除了废弃的string,索引属性只有true/false两种,代替之前的not_analyzed/no

非索引字段的文档值

之前,设置字段属性index:no将禁用文档的值,现在文档值对数字和boolean类型的值总是有效,除非doc_values设置为false

字段映射限制

对索引字段进行限制,最大1000个字段,字段最大深度20层。_parent字段不再索引,为找到文档中引用的父id,可以使用新的parent_id来进行查询。_source映射不再支持格式选项

_all查询的精度

每个字段长度由4个字节压缩到1个字节,空间效率更高,索引时间计算不太准确

percolator类型

percolator字段类型解析json结构到本地并存储到索引中。percolator先存储搜索,然后用文档来进行查询是匹配搜索。

映射percolator字段类型,该类型适用于percolate查询

{"properties":{"query":{"type":"percolator"}}}

下面的json代码段可以被索引为一个本地查询

{"query":{"match":{"field":"value"}}}

一个索引中只能有一个percolator类型字段

1、percolate查询

将存储在索引中的查询进行字段匹配。

PUT /secisland

{"mappings":{"doctype":{"properties":{"message":{"type":"text"}}},"queries":{"properties":{"query":{"type":"percolator"}}}}}

Elasticsearch 6.X中,一个index只能有一个type,推荐的type名是 _doc

PUT /secisland

{"mappings":{"doctype":{"properties":{"message":{"type":"text"},"query":{"type":"percolator"}}}}}

#在percolator中添加一个查询

PUT /secisland/doctype/1?refresh

{"query":{"match":{"message":"bonsai tree"}}}

#在登记的percolator的查询中匹配文档

POST /secisland/_search

{"query": {"percolate": {"field": "query","document": {"message": "A new bonsai tree in the office"}}}}

参数说明:

field,定义percolator字段,必填

document_type,映射的稳定字段,必填;es6中一个索引仅支持一个类型,没有该字段

document,需要匹配的原始文档。也可以在存储在索引中的文档,在这种情况下,文档参数可以被替换为这些参数:index、type、id、routing、preference、version

#添加一条待查询数据

PUT secisland/doctype/2 {"message":"A new bonsai tree in the office"}

#查询可以这样写

GET secisland/_search

{"query":{"percolate":{"field":"query","index":"secisland","type":"doctype","id":"2"}}}

2、percolate查询高亮显示

索引的变化

当运行索引映射的时候禁止关闭或删除索引操作

索引别名不再支持索引路由,同时也不支持搜索路由

接口相关的变化

创建索引的方式只能用PUT

配置相关的变化

node.client设置被移除,若设置节点将无法启动。可以通过分别设置node.master、node.data、node.ingest来设置节点的类型

gateway。format设置被取消,默认用format设置smile

index.analysis.analyzer.default_index不再支持,替代为index.analysis.analyzer.default

通过系统属性配置es进行了调整,通过命令行参数设置将取消、通过java环境变量设置将取消、通过ES_JAVA_OPTS环境变量设置将取消

打包接口的变化

java虚拟机选择参数配置被放在新的配置文件jvm.options中,这意味着通过环境变量设置的参数被取消了

/bin/bash文件被依赖

脚本的变化

默认脚本语言从Groovy到Painless,Painless更安全、更快。语法上的不同在参数上,所有Painless参数必须有一个前缀

script.default_lang被移除,因为系统不再支持默认其他脚本语言,若要使用,需要在请求参数中显式指出

内联脚本将不再被使用;script和script_file参数将不再有效,由基于脚本或者模板的文件file来代替;基于文件的脚本用法将不再有效;script_id参数将不再被使用,由id来代替;模板查询中的query参数将不再被使用,由inline参数代替;搜索模板中的顶层模板template字段被替换为一致的模板/脚本对象语法

HTTP协议的变化

HTTP协议请求压缩始终被支持

所有节点都会写入数据到磁盘,包括node.data:false和node.master:false时

喜欢 (13)or分享 (0)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值