Apache Zeppelin 中 Elasticsearch 解释器

概述

Elasticsearch是一个高度可扩展的开源全文搜索和分析引擎。它允许您快速,实时地存储,搜索和分析大量数据。它通常用作为具有复杂的搜索功能和要求的应用程序提供的底层引擎/技术。

 

配置

属性
默认
描述
elasticsearch.cluster.name elasticsearch 群集名称
elasticsearch.host localhost 集群中节点的主机
elasticsearch.port 9300 连接端口(重要提示:它取决于客户端类型,传输或http)
elasticsearch.client.type transport Elasticsearch(transport或http)的客户端类型(Important:端口取决于此值)
elasticsearch.basicauth.username   基本认证用户名(http)
elasticsearch.basicauth.password   基本认证密码(http)
elasticsearch.result.size 10 搜索查询结果集的大小

注意#1:您可以添加更多属性来配置Elasticsearch客户端。

注意#2:如果使用Shield,您可以添加一个名称为shield.user包含名称和密码(格式:)的值的属性username:password。有关Shield配置的更多详细信息,请参阅Shield参考指南。不要忘记,在解释器目录(ZEPPELIN_HOME/interpreters/elasticsearch)中复制屏蔽客户端jar 。

 

启用弹性搜索解释器

在笔记本中,要启用弹性搜索解释器,请单击齿轮图标,然后选择弹性搜索

 

使用弹性搜索解释器

在段落中,用于%elasticsearch选择Elasticsearch解释器,然后输入所有命令。要获取可用命令的列表,请使用help

% elasticsearch
help
  
Elasticsearch interpreter:
General  format : <command>  / <indices> / <types> / < id > <option> <JSON>
   -  indices:  list  of indices separated by commas (depends on the command)
   -  types:  list  of document types separated by commas (depends on the command)
Commands:
   -  search  / indices / types <query>
     . indices  and  types can be omitted (at least, you have to provide  '/' )
     . a query  is  either a JSON - formatted query, nor a lucene query
   -  size <value>
     . defines the size of the result  set  (default value  is  in  the config)
     if  used, this command must be declared before a search command
   -  count  / indices / types <query>
     . same comments as  for  the search
   -  get  / index / type / id
   -  delete  / index / type / id
   -  index  / index / type / id  <json - formatted document>
     . the  id  can be omitted, elasticsearch will generate one  

 

提示:使用(Ctrl +。)进行自动完成。

得到

使用get命令,您可以通过ID查找文档。结果是一个JSON文档。

% elasticsearch
get  / index / type / id  

 

例: 

搜索

使用该search命令,您可以向Elasticsearch发送搜索查询。有两种查询格式:

  • 您可以提供JSON格式的查询,这正是您在使用Elasticsearch的REST API时提供的。
  • 您还可以提供a的内容query_string

 

% elasticsearch
search  / index1,index2,... / type1,type2,...  <JSON document containing the query  or  query_string elements>  

 

如果要修改结果集的大小,可以在搜索命令之前添加一个设置大小的行。

% elasticsearch
size  50
search  / index1,index2,... / type1,type2,...  <JSON document containing the query  or  query_string elements>  

 

搜索查询还可以包含聚合。如果至少有一个聚合,则显示第一个聚合的结果,否则显示搜索命中。

例子:

  • 使用JSON查询:

    % elasticsearch
    search  /  "query" : {  "match_all" : { } } }
      
    % elasticsearch
    search  / logs {  "query" : {  "query_string" : {  "query" "request.method:GET AND status:200"  } } }
      
    % elasticsearch
    search  / logs {  "aggs" : {
    "content_length_stats" : {
       "extended_stats" : {
         "field" "content_length"
       }
    }
    } } 
  • 使用query_string元素:

    % elasticsearch
    search  / logs request.method:GET AND status: 200
      
    % elasticsearch
    search  / logs ( 404  AND (POST OR DELETE)) 

重要提示:Elasticsearch中的文档是一个JSON文档,因此它是层次结构的,而不是SQL表中的一行。对于弹性解释器,搜索查询的结果是平坦的。

假设我们有一个JSON文档:

{
   "date" "2015-12-08T21:03:13.588Z" ,
   "request" : {
     "method" "GET" ,
     "url" "/zeppelin/4cd001cd-c517-4fa9-b8e5-a06b8f4056c4" ,
     "headers" : [  "Accept: *.*" "Host: apache.org" ]
   },
   "status" "403" ,
   "content_length" 1234
}  

 

数据将如下所示:

CONTENT_LENGTH
日期
request.headers [0]
request.headers [1]
request.method
request.url
状态
1234 2015-12-08T21:03:13.588Z Accept: *.* Host: apache.org GET /zeppelin/4cd001cd-c517-4fa9-b8e5-a06b8f4056c4 403

例子:

  • 包含结果的表格:

  • 您还可以使用预定义的图表: 
  • 使用JSON查询:
  • 使用包含fields参数(用于过滤响应中的字段)的JSON查询:在这种情况下,响应中的所有字段值都是数组,因此,在平坦化结果之后,所有字段名称的格式为field_name[x] 
  • 使用查询字符串: 
  • 使用包含多值度量聚合的查询:
  • 使用包含多桶聚合的查询:

计数

使用该count命令,您可以对某些索引和类型中可用的文档进行计数。您还可以提供查询。

% elasticsearch
count  / index1,index2,... / type1,type2,... <JSON document containing the query OR a query string>  

 

例子:

  • 没有查询: 

  • 有一个查询: 

指数

使用该index命令,您可以在Elasticsearch中插入/更新文档。

% elasticsearch
index  / index / type / id  <JSON document>
  
% elasticsearch
index  / index / type  <JSON document>  

删除

使用该delete命令,您可以删除文档。

% elasticsearch
delete  / index / type / id  

应用Zeppelin动态表单

您可以在查询内使用Zeppelin 动态表单。您可以同时使用text inputselect form参数化功能。

% elasticsearch
size ${limit = 10 }
search  / index / type  "query" : {  "match_all" : { } } } 
 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值