# Elasticsearch 解釋器
原文鏈接 : [http://zeppelin.apache.org/docs/0.7.2/interpreter/elasticsearch.html](http://zeppelin.apache.org/docs/0.7.2/interpreter/elasticsearch.html)
譯文鏈接 : [http://www.apache.wiki/pages/viewpage.action?pageId=10030782](http://www.apache.wiki/pages/viewpage.action?pageId=10030782)
貢獻者 : [片刻](/display/~jiangzhonglian) [ApacheCN](/display/~apachecn) [Apache中文網](/display/~apachechina)
## 概述
[Elasticsearch](https://www.elastic.co/products/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參考指南](https://www.elastic.co/guide/en/shield/current/_using_elasticsearch_java_clients_with_shield.html)。不要忘記,在解釋器目錄(`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時提供的。
* 有關搜索查詢的內容的詳細信息,請參閱[Elasticsearch搜索API參考文檔](https://www.elastic.co/guide/en/elasticsearch/reference/current/search.html)。
* 您還可以提供a的內容`query_string`。
* 這是一個查詢的快捷方式:?`{ "query": { "query_string": { "query": "__HERE YOUR QUERY__", "analyze_wildcard": true } } }`
* 有關[此類查詢](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax)的內容的詳細信息,請參閱[Elasticsearch查詢字符串語法](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax)。
```
%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> ?
```
> 搜索查詢還可以包含[聚合](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html)。如果至少有一個聚合,則顯示第一個聚合的結果,否則顯示搜索命中。
例子:
* 使用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 動態表單](http://www.apache.wiki/pages/viewpage.action?pageId=10030585)。您可以同時使用`text input`和`select form`參數化功能。
```
%elasticsearch
size ${limit=10}
search /index/type { "query": { "match_all": { } } }?
```
- 快速入門
- 什么是Apache Zeppelin?
- 安裝
- 配置
- 探索Apache Zeppelin UI
- 教程
- 動態表單
- 發表你的段落
- 自定義Zeppelin主頁
- 升級Zeppelin版本
- 從源碼編譯
- 使用Flink和Spark Clusters安裝Zeppelin教程
- 解釋器
- 概述
- 解釋器安裝
- 解釋器依賴管理
- 解釋器的模擬用戶
- 解釋員執行Hook(實驗)
- Alluxio 解釋器
- Beam 解釋器
- BigQuery 解釋器
- Cassandra CQL 解釋器
- Elasticsearch 解釋器
- Flink 解釋器
- Geode/Gemfire OQL 解釋器
- HBase Shell 解釋器
- HDFS文件系統 解釋器
- Hive 解釋器
- Ignite 解釋器
- JDBC通用 解釋器
- Kylin 解釋器
- Lens 解釋器
- Livy 解釋器
- Markdown 解釋器
- Pig 解釋器
- PostgreSQL, HAWQ 解釋器
- Python 2&3解釋器
- R 解釋器
- Scalding 解釋器
- Scio 解釋器
- Shell 解釋器
- Spark 解釋器
- 系統顯示
- 系統基本顯示
- 后端Angular API
- 前端Angular API
- 更多
- 筆記本存儲
- REST API
- 解釋器 API
- 筆記本 API
- 筆記本資源 API
- 配置 API
- 憑據 API
- Helium API
- Security ( 安全 )
- Shiro 授權
- 筆記本 授權
- 數據源 授權
- Helium 授權
- Advanced ( 高級 )
- Zeppelin on Vagrant VM ( Zeppelin 在 Vagrant 虛擬機上 )
- Zeppelin on Spark Cluster Mode( Spark 集群模式下的 Zeppelin )
- Zeppelin on CDH ( Zeppelin 在 CDH 上 )
- Contibute ( 貢獻 )
- Writing a New Interpreter ( 寫一個新的解釋器 )
- Writing a new Visualization (Experimental) ( 編寫新的可視化(實驗) )
- Writing a new Application (Experimental) ( 寫一個新的應用程序( 實驗 ) )
- Contributing to Apache Zeppelin ( Code ) ( 向 Apache Zeppelin 貢獻( 代碼 ) )
- Contributing to Apache Zeppelin ( Website ) ( 向 Apache Zeppelin 貢獻(website) )