elasticsearch 第一篇(入门篇)
介紹
elasticsearch是一個(gè)高效的、可擴(kuò)展的全文搜索引擎
基本概念
- Near Realtime(NRT): es是一個(gè)接近實(shí)時(shí)查詢平臺(tái),意味從存儲(chǔ)一條數(shù)據(jù)到可以索引到數(shù)據(jù)時(shí)差很小,通常在1s內(nèi)
- Cluster: es是一個(gè)分布式、可擴(kuò)展的平臺(tái), 可由一個(gè)或多個(gè)服務(wù)器通過定義的cluster.name(默認(rèn)為elasticsearch)標(biāo)識(shí)共建同一個(gè)集群
- Node: 通常一臺(tái)服務(wù)器上部署一臺(tái)es node,作為集群的一部分,用于數(shù)據(jù)的存儲(chǔ)和提供搜索功能,在一個(gè)集群中節(jié)點(diǎn)通過node.name區(qū)分,默認(rèn)在node啟動(dòng)時(shí)隨機(jī)生成一個(gè)的字符串做為節(jié)點(diǎn)名稱,可配置
- Index: 類似于關(guān)系型數(shù)據(jù)庫(kù)中的database,用于組織一類功能相似的數(shù)據(jù),在一個(gè)集群中可以定義任意個(gè)索引,索引的名稱只能由小寫字母組成,在數(shù)據(jù)索引,更新,搜索,刪除時(shí)作為數(shù)據(jù)標(biāo)識(shí)的一部分
- Type: 類似于關(guān)系型數(shù)據(jù)庫(kù)中的table,在Index中可以定義多個(gè)Type,原則上一個(gè)Type是由相同屬性組成的數(shù)據(jù)集合
- Document: 類似于關(guān)系型數(shù)據(jù)庫(kù)中的record,是數(shù)據(jù)的最基本存儲(chǔ)單元,使用json形式表示,Document在物理上存儲(chǔ)在Index下,但是在邏輯上會(huì)分配到具體的Type下
- Shards & Replica:
一個(gè)Index可能存儲(chǔ)大量的數(shù)據(jù)(超過單個(gè)節(jié)點(diǎn)的硬件限制),不管是數(shù)據(jù)存儲(chǔ)還是數(shù)據(jù)索引,為解決數(shù)據(jù)單節(jié)點(diǎn)存儲(chǔ)并提高并發(fā),es將每一個(gè)Index物理分為多個(gè)片,從而水平擴(kuò)展存儲(chǔ)容量,提高并發(fā)(可以同時(shí)對(duì)個(gè)shard進(jìn)行索引和搜索)
為防止某個(gè)存儲(chǔ)單元出現(xiàn)故障后數(shù)據(jù)不能索引的情況,es提供將shard進(jìn)行復(fù)制功能,將主shard出現(xiàn)故障后,復(fù)制shard替代主shard進(jìn)行數(shù)據(jù)索引操作,已此方式實(shí)現(xiàn)其高可用性,因?yàn)樵谒阉鲿r(shí)可以使用復(fù)制shard,從而提高的數(shù)據(jù)搜索的并發(fā)性
在Index創(chuàng)建時(shí)可以進(jìn)行分片數(shù)量和復(fù)制數(shù)量的設(shè)置,默認(rèn)創(chuàng)建每個(gè)Index設(shè)置5個(gè)shard和1個(gè)Replica,表示該Index由5個(gè)邏輯存儲(chǔ)單元進(jìn)行存儲(chǔ),每個(gè)邏輯存儲(chǔ)單元具有一個(gè)復(fù)制節(jié)點(diǎn)進(jìn)行備災(zāi),注意,shard只能在創(chuàng)建Index時(shí)進(jìn)行設(shè)置,shard數(shù)量與document分配到哪個(gè)shard上存儲(chǔ)有關(guān)(通常使用hash(document _id) % shard num計(jì)算 document存儲(chǔ)在哪個(gè)shard上)
在es將主shard和replic分片在不同的Node上
安裝
- elasticsearch使用java語(yǔ)言實(shí)現(xiàn),在使用時(shí)必須安裝java虛擬機(jī)(目前es1.6和1.7版本均可選擇1.8版本java)
- 下載地址
- 解壓到安裝目錄?C:\Program Files\elasticsearch
- 運(yùn)行?cd "C:\Program Files\elasticsearch\bin" && elasticsearch.bat
- 安裝到服務(wù)?service install elasticsearch
- 啟動(dòng)服務(wù)?net start elasticsearch
- 停止服務(wù)?net stop elasticsearch
- 測(cè)試
訪問地址:?http://localhost:9200
訪問結(jié)果:1 2 3 4 5 6 7 8 9 10 11 12 13 { status: 200, name: "Smart Alec", cluster_name: "elasticsearch", version: { number: "1.6.0", build_hash: "cdd3ac4dde4f69524ec0a14de3828cb95bbb86d0", build_timestamp: "2015-06-09T13:36:34Z", build_snapshot: false, lucene_version: "4.10.4" }, tagline: "You Know, for Search" }
接口
es對(duì)外提供標(biāo)準(zhǔn)RESTAPI接口,使用他進(jìn)行集群的所有操作:
- 集群、節(jié)點(diǎn)、索引的狀態(tài)和統(tǒng)計(jì)信息查看
- 管理集群、節(jié)點(diǎn)、索引和類型
- 執(zhí)行CURD操作(創(chuàng)建,更新,讀取,刪除)和索引
- 執(zhí)行高級(jí)搜索功能,比如排序,分頁(yè),篩選,聚合,js腳本執(zhí)行等
格式:curl -X<REST verb> <Node>:<Port>/<Index>/<Type>/<ID>
使用marvel插件
- 運(yùn)行?cd "C:\Program Files\elasticsearch\bin" && plugin -i elasticsearch/marvel/latest
- 訪問地址
- marvel提供sense工具調(diào)用es的RESTAPI借口,?訪問地址, 以下操作使用sense或使用linux curl命令行練習(xí)
狀態(tài)查詢
- 集群狀態(tài)查詢
輸入:?GET _cat/health?v
輸出:1 2 epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks 1442227489 18:44:49 elasticsearch yellow 1 1 50 50 0 0 50 0
說明:
status:表示集群的健康狀態(tài),值可能為green,yellow,red, green表示主shard和replica(至少一個(gè))正常,yellow表示主shard正常但replica都不正常,red表示有的主shard和replica都有問題
node.total:表示集群中節(jié)點(diǎn)的數(shù)量
- 節(jié)點(diǎn)狀態(tài)查詢
輸入:?GET /_cat/nodes?v
輸出:1 2 host ip heap.percent ram.percent load node.role master name silence 192.168.1.111 30 51 d * Thunderbird
查詢所有索引
輸入:?GET /_cat/indices?v
輸出:
| 1 2 3 | health status index pri rep docs.count docs.deleted store.size pri.store.size yellow open .marvel-2015.09.02 1 1 93564 0 78.4mb 78.4mb yellow open .marvel-2015.09.01 1 1 39581 0 45.9mb 45.9mb |
創(chuàng)建索引
輸入:?PUT /test1?pretty
輸出:
| 1 2 3 | { "acknowledged" : true } |
查詢所有索引:
| 1 2 | health status index pri rep docs.count docs.deleted store.size pri.store.size yellow open test1 5 1 0 0 575b 575b |
說明:
health:由于只運(yùn)行一個(gè)節(jié)點(diǎn),replica不能與主shard在同一node中,因此replica不正常,該index的狀態(tài)為yellow
index:為索引名稱
pri:表示主shard個(gè)數(shù)
rep:表示每個(gè)shard的復(fù)制個(gè)數(shù)
docs.count:表示index中document的個(gè)數(shù)
索引、讀取、刪除文檔
索引文檔
- 方法1:
輸入:1 2 PUT user/1?pretty {"name": "silence1"}
輸出:
| 1 2 3 4 5 6 7 | { "_index" : "test1 "_type" : "user", "_id" : "1", "_version" : 1, "created" : true } |
- 方法2:
輸入:1 2 POST user/2?pretty {"name": "silence2"}
輸出:
| 1 2 3 4 5 6 7 | { "_index" : "test1", "_type" : "user", "_id" : "2", "_version" : 1, "created" : true } |
- 方法3:
輸入:1 2 POST user?pretty {"name": "silence3"}
輸出:
| 1 2 3 4 5 6 7 | { "_index" : "test1", "_type" : "user", "_id" : "AU_MdQoXRYiHSIs7UGBQ", "_version" : 1, "created" : true } |
說明: 在索引文檔時(shí)若需要指定文檔ID值則需要使用PUT或者POST提交數(shù)據(jù)并顯示指定ID值,若需要由es自動(dòng)生成ID,則需要使用POST提交數(shù)據(jù)
讀取文檔:
輸入:?GET /test1/user/1?pretty
輸出:
| 1 2 3 4 5 6 7 8 | { "_index" : "test1", "_type" : "user", "_id" : "1", "_version" : 1, "found" : true, "_source":{"name": "silence1"} } |
說明:
_index,_type:表示文檔存儲(chǔ)的Index和Type信息
_id:表示文檔的編號(hào)
_version:表示文檔的版本號(hào),主要用于并發(fā)處理時(shí)使用樂觀鎖防止臟數(shù)據(jù)
found:表示請(qǐng)求的文檔是否存在
_souce:格式為json,為文檔的內(nèi)容
注意:在之前我們并未創(chuàng)建user的Type,在進(jìn)行文檔索引時(shí)自動(dòng)創(chuàng)建了user,在es中可以不顯示的創(chuàng)建Index和Type而使用默認(rèn)參數(shù)或者根據(jù)提交數(shù)據(jù)自定義,但不建議這么使用,在不清楚可能導(dǎo)致什么情況時(shí)顯示創(chuàng)建Index和Type并設(shè)置參數(shù)
刪除文檔:
輸入:?DELETE /test1/user/1?pretty
輸出:
| 1 2 3 4 5 6 7 | { "found" : true, "_index" : "test1", "_type" : "user", "_id" : "1", "_version" : 2 } |
再次讀取文檔輸出:
| 1 2 3 4 5 6 | { "_index" : "test1", "_type" : "user", "_id" : "1", "found" : false } |
刪除索引
輸入:?DELETE /test1?pretty
輸出:
| 1 2 3 | { "acknowledged" : true } |
修改文檔
初始化文檔輸入:
| 1 2 | PUT user/1?pretty {"name" : "silence2", "age":28} |
修改文檔輸入:
| 1 2 | PUT user/1?pretty {"name" : "silence1"} |
讀取文檔輸出:
| 1 2 3 4 5 6 7 8 | { "_index" : "test1", "_type" : "user", "_id" : "1", "_version" : 2, "found" : true, "_source":{"name" : "silence1"} } |
更新文檔
更新數(shù)據(jù)輸入:
| 1 2 | POST /test1/user/1/_update?pretty {"doc" : {"name" : "silence3", "age":28}} |
讀取數(shù)據(jù)輸出:
| 1 2 3 4 5 6 7 8 | { "_index" : "test1", "_type" : "user", "_id" : "1", "_version" : 3, "found" : true, "_source":{"name":"silence3","age":28} } |
更新文檔輸入:
| 1 2 | POST user/1/_update?pretty {"script" : "ctx._source.age += 1"} |
讀取文檔輸出:
| 1 2 3 4 5 6 7 8 | { "_index" : "test1", "_type" : "user", "_id" : "1", "_version" : 4, "found" : true, "_source":{"name":"silence3","age":29} } |
說明:需要POST使用script則必須在elasticsearch/config/elasticsearch.yml配置script.groovy.sandbox.enabled: true
修改(PUT)和更新(POST+_update)的區(qū)別在于修改使用提交的文檔覆蓋es中的文檔,更新使用提交的參數(shù)值覆蓋es中文檔對(duì)應(yīng)的參數(shù)值
根據(jù)查詢刪除文檔
輸入:
| 1 2 | DELETE /test1/user/_query?pretty {"query" : {"match" : {"name" : "silence3"}}} |
輸出:
| 1 2 3 4 5 6 7 8 9 10 11 | { "_indices" : { "test1" : { "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 } } } } |
獲取文檔數(shù)量
輸入:?GET /test1/user/_count?pretty
輸出:
| 1 2 3 4 5 6 7 8 | { "count" : 0, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 } } |
批量操作
輸入:
| 1 2 3 4 5 6 7 8 9 | POST /test1/user/_bulk?pretty {"index" : {"_id" : 1}} {"name" : "silence1"} {"index" : {"_id" : 2}} {"name" : "silence2"} {"index" : {}} {"name" : "silence3"} {"index" : {}} {"name" : "silence4"} |
輸入:
| 1 2 3 4 | POST /test1/user/_bulk?pretty {"update" : {"_id" : 1}} {"doc" : {"age" : 28}} {"delete" : {"_id" : 2}} |
通過文件導(dǎo)入數(shù)據(jù):?curl -XPOST "localhost:9200/test1/account/_bulk?pretty" --data-binary @accounts.json
Query查詢
查詢可以通過兩種方式進(jìn)行,一種為使用查詢字符串進(jìn)行提交參數(shù)查詢,一種為使用RESTAPI提交requesbody提交參數(shù)查詢
獲取所有文檔輸入:?GET /test1/user/_search?q=*&pretty
| 1 2 3 4 | POST /test1/user/_search?pretty { "query" : {"match_all" : {}} } |
輸出:
| 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 40 41 42 43 | { "took": 2, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 3, "max_score": 1, "hits": [ { "_index": "test1", "_type": "user", "_id": "1", "_score": 1, "_source": { "name": "silence1", "age": 28 } }, { "_index": "test1", "_type": "user", "_id": "AU_M2zgwLNdQvgqQS3MP", "_score": 1, "_source": { "name": "silence3" } }, { "_index": "test1", "_type": "user", "_id": "AU_M2zgwLNdQvgqQS3MQ", "_score": 1, "_source": { "name": "silence4" } } ] } } |
說明:
took: 執(zhí)行查詢的時(shí)間(單位為毫秒)
timed_out: 執(zhí)行不能超時(shí)
_shards: 提示有多少shard參與查詢以及查詢成功和失敗shard數(shù)量
hits: 查詢結(jié)果
hits.total: 文檔總數(shù)
_score, max_score: 為文檔與查詢條件匹配度和最大匹配度
Query SDL
輸入:
| 1 2 3 4 5 6 7 8 9 | POST /test1/account/_search?pretty { "query" : {"match_all":{}}, "size": 2, "from" : 6, "sort" : { "age" : {"order" : "asc"} } } |
說明:
query: 用于定義查詢條件過濾
match_all: 表示查詢所有文檔
size: 表示查詢返回文檔數(shù)量,若未設(shè)置默認(rèn)為10
from: 表示開始位置, es使用0作為開始索引,常與size組合進(jìn)行分頁(yè)查詢,若未設(shè)置默認(rèn)為0
sort: 用于設(shè)置排序?qū)傩院鸵?guī)則
- 使用_source設(shè)置查詢結(jié)果返回的文檔屬性
輸入:1 2 3 4 5 6 7 POST /test1/account/_search?pretty { "query": { "match_all": {} }, "_source":["firstname", "lastname", "age"] }
輸出:
| 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 | { "took": 5, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1000, "max_score": 1, "hits": [ { "_index": "test1", "_type": "account", "_id": "4", "_score": 1, "_source": { "firstname": "Rodriquez", "age": 31, "lastname": "Flores" } }, { "_index": "test1", "_type": "account", "_id": "9", "_score": 1, "_source": { "firstname": "Opal", "age": 39, "lastname": "Meadows" } } ] } } |
- 使用match設(shè)置查詢匹配值
輸入:1 2 3 4 5 6 7 POST /test1/account/_search?pretty { "query": { "match": {"address" : "986 Wyckoff Avenue"} }, "size" : 2 }
輸出:
| 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | { "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 216, "max_score": 4.1231737, "hits": [ { "_index": "test1", "_type": "account", "_id": "4", "_score": 4.1231737, "_source": { "account_number": 4, "balance": 27658, "firstname": "Rodriquez", "lastname": "Flores", "age": 31, "gender": "F", "address": "986 Wyckoff Avenue", "employer": "Tourmania", "email": "rodriquezflores@tourmania.com", "city": "Eastvale", "state": "HI" } }, { "_index": "test1", "_type": "account", "_id": "34", "_score": 0.59278774, "_source": { "account_number": 34, "balance": 35379, "firstname": "Ellison", "lastname": "Kim", "age": 30, "gender": "F", "address": "986 Revere Place", "employer": "Signity", "email": "ellisonkim@signity.com", "city": "Sehili", "state": "IL" } } ] } } |
說明:根據(jù)查詢結(jié)果可見在查詢結(jié)果中并非只查詢address包含”986 Wyckoff Avenue”的文檔,而是包含986,wychoff,Avenue三個(gè)詞中任意一個(gè),這就是es分詞的強(qiáng)大之處
可見查詢結(jié)果中_score(與查詢條件匹配度)按從大到小的順序排列
此時(shí)你可能想要值查詢address包含”986 Wyckoff Avenue”的文檔,怎么辦呢?使用match_phrase
輸入:
| 1 2 3 4 5 6 | POST /test1/account/_search?pretty { "query": { "match_phrase": {"address" : "986 Wyckoff Avenue"} } } |
可能你已經(jīng)注意到, 以上query中只有一個(gè)條件,若存在多個(gè)條件,我們必須使用bool query將多個(gè)條件進(jìn)行組合
輸入:
| 1 2 3 4 5 6 7 8 9 10 11 | POST /test1/account/_search?pretty { "query": { "bool" : { "must":[ {"match_phrase": {"address" : "986 Wyckoff Avenue"}}, {"match" : {"age" : 31}} ] } } } |
說明: 查詢所有條件都滿足的結(jié)果
輸入:
| 1 2 3 4 5 6 7 8 9 10 11 | POST /test1/account/_search { "query": { "bool" : { "should":[ {"match_phrase": {"address" : "986 Wyckoff Avenue"}}, {"match_phrase": {"address" : "963 Neptune Avenue"}} ] } } } |
說明: 查詢有一個(gè)條件滿足的結(jié)果
輸入:
| 1 2 3 4 5 6 7 8 9 10 11 | POST /test1/account/_search { "query": { "bool" : { "must_not":[ {"match": {"city" : "Eastvale"}}, {"match": {"city" : "Olney"}} ] } } } |
說明: 查詢有條件都不滿足的結(jié)果
在Query SDL中可以將must, must_not和should組合使用
輸入:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 | POST /test1/account/_search { "query": { "bool" : { "must": [{ "match" : {"age":20} }], "must_not":[ {"match": {"city" : "Steinhatchee"}} ] } } } |
Filters 查詢
在使用Query 查詢時(shí)可以看到在查詢結(jié)果中都有_score值, _score值需要進(jìn)行計(jì)算, 在某些情況下我們并不需要_socre值,在es中提供了Filters查詢,它類似于Query查詢,但是效率較高,原因:
- range 過濾器, 用于設(shè)置條件在某個(gè)范圍內(nèi)
輸入:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 POST /test1/account/_search?pretty { "query": { "filtered":{ "query": { "match_all" : {} }, "filter": { "range" : { "age" : { "gte" : 20, "lt" : 28 } } } } } }
判斷使用filter還是使用query的最簡(jiǎn)單方法就是是否關(guān)注_score值,若關(guān)注則使用query,若不關(guān)注則使用filter
聚合分析
es提供Aggregations支持分組和聚合查詢,類似于關(guān)系型數(shù)據(jù)庫(kù)中的GROUP BY和聚合函數(shù),在ES調(diào)用聚合RESTAPI時(shí)返回結(jié)果包含文檔查詢結(jié)果和聚合結(jié)果,也可以返回多個(gè)聚合結(jié)果,從而簡(jiǎn)化API調(diào)用和減少網(wǎng)絡(luò)流量使用
輸入:
| 1 2 3 4 5 6 7 8 9 | POST /test1/account/_search?pretty { "size" : 0, "aggs" : { "group_by_gender" : { "terms" : {"field":"gender"} } } } |
輸出:
| 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 | { "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1000, "max_score": 0, "hits": [] }, "aggregations": { "group_by_gender": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "m", "doc_count": 507 }, { "key": "f", "doc_count": 493 } ] } } } |
說明:
size: 返回文檔查詢結(jié)果數(shù)量
aggs: 用于設(shè)置聚合分類
terms: 設(shè)置group by屬性值
輸入:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | POST /test1/account/_search?pretty { "size" : 0, "aggs" : { "group_by_gender" : { "terms" : { "field":"state", "order" : {"avg_age":"desc"}, "size" : 3 }, "aggs" : { "avg_age" : { "avg" : {"field" : "age"} }, "max_age" : { "max" : {"field": "age"} }, "min_age" : { "min": {"field":"age"} } } } } } |
輸出:
| 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | { "took": 9, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1000, "max_score": 0, "hits": [] }, "aggregations": { "group_by_gender": { "doc_count_error_upper_bound": -1, "sum_other_doc_count": 992, "buckets": [ { "key": "de", "doc_count": 1, "max_age": { "value": 37 }, "avg_age": { "value": 37 }, "min_age": { "value": 37 } }, { "key": "il", "doc_count": 3, "max_age": { "value": 39 }, "avg_age": { "value": 36.333333333333336 }, "min_age": { "value": 32 } }, { "key": "in", "doc_count": 4, "max_age": { "value": 39 }, "avg_age": { "value": 36 }, "min_age": { "value": 34 } } ] } } } |
說明:根據(jù)state進(jìn)行分類,并查詢每種分類所有人員的最大,最小,平均年齡, 查詢結(jié)果按平均年齡排序并返回前3個(gè)查詢結(jié)果
若需要按照分類總數(shù)進(jìn)行排序時(shí)可以使用_count做為sort的field值
在聚合查詢時(shí)通過size設(shè)置返回的TOP數(shù)量,默認(rèn)為10
在聚合查詢中可任意嵌套聚合語(yǔ)句進(jìn)行查詢
輸入:
| 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 | POST /test1/account/_search?pretty { "size" : 0, "aggs" : { "group_by_age" : { "range" : { "field": "age", "ranges" : [{ "from" : 20, "to" : 30 }, { "from": 30, "to" : 40 },{ "from": 40, "to": 50 }] }, "aggs":{ "group_by_gender" : { "terms" : {"field": "gender"}, "aggs" : { "group_by_balance" :{ "range" : { "field":"balance", "ranges" : [{ "to" : 5000 }, { "from" : 5000 } ] } } } } } } } } |
輸出:
| 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | { "took": 1, "timed_out": false, "_shards": { "total": 5, "successful": 5, "failed": 0 }, "hits": { "total": 1000, "max_score": 0, "hits": [] }, "aggregations": { "group_by_age": { "buckets": [ { "key": "20.0-30.0", "from": 20, "from_as_string": "20.0", "to": 30, "to_as_string": "30.0", "doc_count": 451, "group_by_gender": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "m", "doc_count": 232, "group_by_balance": { "buckets": [ { "key": "*-5000.0", "to": 5000, "to_as_string": "5000.0", "doc_count": 9 }, { "key": "5000.0-*", "from": 5000, "from_as_string": "5000.0", "doc_count": 223 } ] } }, { "key": "f", "doc_count": 219, "group_by_balance": { "buckets": [ { "key": "*-5000.0", "to": 5000, "to_as_string": "5000.0", "doc_count": 20 }, { "key": "5000.0-*", "from": 5000, "from_as_string": "5000.0", "doc_count": 199 } ] } } ] } }, { "key": "30.0-40.0", "from": 30, "from_as_string": "30.0", "to": 40, "to_as_string": "40.0", "doc_count": 504, "group_by_gender": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "f", "doc_count": 253, "group_by_balance": { "buckets": [ { "key": "*-5000.0", "to": 5000, "to_as_string": "5000.0", "doc_count": 26 }, { "key": "5000.0-*", "from": 5000, "from_as_string": "5000.0", "doc_count": 227 } ] } }, { "key": "m", "doc_count": 251, "group_by_balance": { "buckets": [ { "key": "*-5000.0", "to": 5000, "to_as_string": "5000.0", "doc_count": 21 }, { "key": "5000.0-*", "from": 5000, "from_as_string": "5000.0", "doc_count": 230 } ] } } ] } }, { "key": "40.0-50.0", "from": 40, "from_as_string": "40.0", "to": 50, "to_as_string": "50.0", "doc_count": 45, "group_by_gender": { "doc_count_error_upper_bound": 0, "sum_other_doc_count": 0, "buckets": [ { "key": "m", "doc_count": 24, "group_by_balance": { "buckets": [ { "key": "*-5000.0", "to": 5000, "to_as_string": "5000.0", "doc_count": 3 }, { "key": "5000.0-*", "from": 5000, "from_as_string": "5000.0", "doc_count": 21 } ] } }, { "key": "f", "doc_count": 21, "group_by_balance": { "buckets": [ { "key": "*-5000.0", "to": 5000, "to_as_string": "5000.0", "doc_count": 0 }, { "key": "5000.0-*", "from": 5000, "from_as_string": "5000.0", "doc_count": 21 } ] } } ] } } ] } } } |
使用head插件
- 運(yùn)行?cd "C:\Program Files\elasticsearch\bin" && plugin -install mobz/elasticsearch-head
- 訪問地址
總結(jié)
以上是生活随笔為你收集整理的elasticsearch 第一篇(入门篇)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: elasticsearch 第二篇(配置
- 下一篇: elasticsearch 第四篇(AP