零灰伟、Basic Concept
ES存儲方式
它是面向文檔的(Document oriented),它存儲整個(gè)對象或文檔,并且索引每個(gè)文檔的內(nèi)容,使之可以被檢索赔退。Elasticsearch使用JSON作為文檔的序列化格式。ES索引
關(guān)系型數(shù)據(jù)庫通過增加一個(gè)索引钢颂,比如一個(gè)B-樹 索引到指定的列上经窖,以便提升數(shù)據(jù)檢索速度。Elasticsearch 和lucene使用了一個(gè)叫排序索引的結(jié)構(gòu)達(dá)到相同的目的彭沼。ES文檔
Elasticsearch中文檔(Document)是指最頂層或者根對象 這個(gè)根對象被序列化成 JSON 并存儲到 Elasticsearch 中缔逛,指定了唯一 ID。文檔包含它的數(shù)據(jù)以及它的元數(shù)據(jù)(文檔本身信息)姓惑。
文檔三個(gè)必須的元數(shù)據(jù):_index, _type, _id 即文檔存在哪兒褐奴,文檔的類型,文檔唯一標(biāo)識符于毙。ES VS 關(guān)系型數(shù)據(jù)庫
Elasticsearch的 index --> DB 敦冬,
Elasticsearch的type --> table,
Elasticsearch的Document -->對應(yīng)table的一行記錄row唯沮,
Document的Field --> table里面的column
“Relational DB -> Databases -> Tables -> Rows -> Columns
Elasticsearch -> Indices -> Types -> Documents -> Fields”
一脖旱、Elasticsearch 搜索初識
- 搜索accounts的下所有post
$ curl -XGET 'localhost:9200/accounts/post/_search?pretty'
- 搜索accounts下特定的post
$ curl -XGET 'localhost:9200/accounts/post/_search?q=tag:elasticsearch'
- 使用DSL(Domain Specific Language)查詢堪遂,ES有一些高級查詢包括 aggregation,短語搜索萌庆,跟SQL 中g(shù)roup by ,like 等類似溶褪。當(dāng)然還有逼格更高的模糊查詢,匹配度之類的践险。
curl -XGET 'localhost:9200/megacorp/employee/_search?pretty' -H 'Content-Type: application/json' -d'
{
"query" : {
"match" : {
"tag" : "elasticsearch"
}
}
}
'
二猿妈、分布式(cluster, node, shared)
一個(gè)節(jié)點(diǎn)(node),就是一個(gè)Elasticsearch實(shí)例,集群(cluster)由一個(gè)或多個(gè)節(jié)點(diǎn)組成巍虫,節(jié)點(diǎn)有相同的cluster.name于游。當(dāng)新加入或者刪除節(jié)點(diǎn)時(shí),集群會感知并平衡數(shù)據(jù)垫言。
一個(gè)分片(shared)是一個(gè)最小級別 worker unit贰剥。文檔存儲在分片中,然后分配到集群的節(jié)點(diǎn)上筷频。分片分為primary shared 和replica shared蚌成。每個(gè)文檔屬于單獨(dú)的primary shared。replica shared只是主分片的一個(gè)副本凛捏。
測試集群健康
curl -XGET 'localhost:9200/_cluster/health?pretty'
三担忧、參考鏈接
[ElasticSearch 官方網(wǎng)站](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html)