## 什么是文檔?
程序中大多的實體或對象能夠被序列化為包含鍵值對的JSON對象,**鍵(key)**是**字段(field)**或**屬性(property)**的名字,**值(value)**可以是字符串、數字、布爾類型、另一個對象、值數組或者其他特殊類型,比如表示日期的字符串或者表示地理位置的對象。
```Javascript
{
"name": "John Smith",
"age": 42,
"confirmed": true,
"join_date": "2014-06-01",
"home": {
"lat": 51.5,
"lon": 0.1
},
"accounts": [
{
"type": "facebook",
"id": "johnsmith"
},
{
"type": "twitter",
"id": "johnsmith"
}
]
}
```
通常,我們可以認為**對象(object)**和**文檔(document)**是等價相通的。不過,他們還是有所差別:對象(Object)是一個JSON結構體——類似于哈希、hashmap、字典或者關聯數組;對象(Object)中還可能包含其他對象(Object)。
在Elasticsearch中,**文檔(document)**這個術語有著特殊含義。它特指最頂層結構或者**根對象(root object)**序列化成的JSON數據(以唯一ID標識并存儲于Elasticsearch中)。
## 文檔元數據
一個文檔不只有數據。它還包含了**元數據(metadata)**——**關于**文檔的信息。三個必須的元數據節點是:
| 節點 | 說明 |
| -------- | ------------------ |
| `_index` | 文檔存儲的地方 |
| `_type` | 文檔代表的對象的類 |
| `_id` | 文檔的唯一標識 |
### `_index`
**索引(index)**類似于關系型數據庫里的“數據庫”——它是我們存儲和索引關聯數據的地方。
> 提示:
> 事實上,我們的數據被存儲和索引在**分片(shards)**中,索引只是一個把一個或多個分片分組在一起的邏輯空間。然而,這只是一些內部細節——我們的程序完全不用關心分片。對于我們的程序而言,文檔存儲在**索引(index)**中。剩下的細節由Elasticsearch關心既可。
我們將會在《索引管理》章節中探討如何創建并管理索引,但現在,我們將讓Elasticsearch為我們創建索引。我們唯一需要做的僅僅是選擇一個索引名。這個名字必須是全部小寫,不能以下劃線開頭,不能包含逗號。讓我們使用`website`做為索引名。
### `_type`
在應用中,我們使用對象表示一些“事物”,例如一個用戶、一篇博客、一個評論,或者一封郵件。每個對象都屬于一個**類(class)**,這個類定義了屬性或與對象關聯的數據。`user`類的對象可能包含姓名、性別、年齡和Email地址。
在關系型數據庫中,我們經常將相同類的對象存儲在一個表里,因為它們有著相同的結構。同理,在Elasticsearch中,我們使用相同**類型(type)**的文檔表示相同的“事物”,因為他們的數據結構也是相同的。
每個**類型(type)**都有自己的**映射(mapping)**或者結構定義,就像傳統數據庫表中的列一樣。所有類型下的文檔被存儲在同一個索引下,但是類型的**映射(mapping)**會告訴Elasticsearch不同的文檔如何被索引。
我們將會在《映射》章節探討如何定義和管理映射,但是現在我們將依賴Elasticsearch去自動處理數據結構。
`_type`的名字可以是大寫或小寫,不能包含下劃線或逗號。我們將使用`blog`做為類型名。
### `_id`
**id**僅僅是一個字符串,它與`_index`和`_type`組合時,就可以在Elasticsearch中唯一標識一個文檔。當創建一個文檔,你可以自定義`_id`,也可以讓Elasticsearch幫你自動生成。
### 其它元數據
還有一些其它的元數據,我們將在《映射》章節探討。使用上面提到的元素,我們已經可以在Elasticsearch中存儲文檔并通過ID檢索——換言說,把Elasticsearch做為文檔存儲器使用了。
- Introduction
- 入門
- 是什么
- 安裝
- API
- 文檔
- 索引
- 搜索
- 聚合
- 小結
- 分布式
- 結語
- 分布式集群
- 空集群
- 集群健康
- 添加索引
- 故障轉移
- 橫向擴展
- 更多擴展
- 應對故障
- 數據
- 文檔
- 索引
- 獲取
- 存在
- 更新
- 創建
- 刪除
- 版本控制
- 局部更新
- Mget
- 批量
- 結語
- 分布式增刪改查
- 路由
- 分片交互
- 新建、索引和刪除
- 檢索
- 局部更新
- 批量請求
- 批量格式
- 搜索
- 空搜索
- 多索引和多類型
- 分頁
- 查詢字符串
- 映射和分析
- 數據類型差異
- 確切值對決全文
- 倒排索引
- 分析
- 映射
- 復合類型
- 結構化查詢
- 請求體查詢
- 結構化查詢
- 查詢與過濾
- 重要的查詢子句
- 過濾查詢
- 驗證查詢
- 結語
- 排序
- 排序
- 字符串排序
- 相關性
- 字段數據
- 分布式搜索
- 查詢階段
- 取回階段
- 搜索選項
- 掃描和滾屏
- 索引管理
- 創建刪除
- 設置
- 配置分析器
- 自定義分析器
- 映射
- 根對象
- 元數據中的source字段
- 元數據中的all字段
- 元數據中的ID字段
- 動態映射
- 自定義動態映射
- 默認映射
- 重建索引
- 別名
- 深入分片
- 使文本可以被搜索
- 動態索引
- 近實時搜索
- 持久化變更
- 合并段
- 結構化搜索
- 查詢準確值
- 組合過濾
- 查詢多個準確值
- 包含,而不是相等
- 范圍
- 處理 Null 值
- 緩存
- 過濾順序
- 全文搜索
- 匹配查詢
- 多詞查詢
- 組合查詢
- 布爾匹配
- 增加子句
- 控制分析
- 關聯失效
- 多字段搜索
- 多重查詢字符串
- 單一查詢字符串
- 最佳字段
- 最佳字段查詢調優
- 多重匹配查詢
- 最多字段查詢
- 跨字段對象查詢
- 以字段為中心查詢
- 全字段查詢
- 跨字段查詢
- 精確查詢
- 模糊匹配
- Phrase matching
- Slop
- Multi value fields
- Scoring
- Relevance
- Performance
- Shingles
- Partial_Matching
- Postcodes
- Prefix query
- Wildcard Regexp
- Match phrase prefix
- Index time
- Ngram intro
- Search as you type
- Compound words
- Relevance
- Scoring theory
- Practical scoring
- Query time boosting
- Query scoring
- Not quite not
- Ignoring TFIDF
- Function score query
- Popularity
- Boosting filtered subsets
- Random scoring
- Decay functions
- Pluggable similarities
- Conclusion
- Language intro
- Intro
- Using
- Configuring
- Language pitfalls
- One language per doc
- One language per field
- Mixed language fields
- Conclusion
- Identifying words
- Intro
- Standard analyzer
- Standard tokenizer
- ICU plugin
- ICU tokenizer
- Tidying text
- Token normalization
- Intro
- Lowercasing
- Removing diacritics
- Unicode world
- Case folding
- Character folding
- Sorting and collations
- Stemming
- Intro
- Algorithmic stemmers
- Dictionary stemmers
- Hunspell stemmer
- Choosing a stemmer
- Controlling stemming
- Stemming in situ
- Stopwords
- Intro
- Using stopwords
- Stopwords and performance
- Divide and conquer
- Phrase queries
- Common grams
- Relevance
- Synonyms
- Intro
- Using synonyms
- Synonym formats
- Expand contract
- Analysis chain
- Multi word synonyms
- Symbol synonyms
- Fuzzy matching
- Intro
- Fuzziness
- Fuzzy query
- Fuzzy match query
- Scoring fuzziness
- Phonetic matching
- Aggregations
- overview
- circuit breaker fd settings
- filtering
- facets
- docvalues
- eager
- breadth vs depth
- Conclusion
- concepts buckets
- basic example
- add metric
- nested bucket
- extra metrics
- bucket metric list
- histogram
- date histogram
- scope
- filtering
- sorting ordering
- approx intro
- cardinality
- percentiles
- sigterms intro
- sigterms
- fielddata
- analyzed vs not
- 地理坐標點
- 地理坐標點
- 通過地理坐標點過濾
- 地理坐標盒模型過濾器
- 地理距離過濾器
- 緩存地理位置過濾器
- 減少內存占用
- 按距離排序
- Geohashe
- Geohashe
- Geohashe映射
- Geohash單元過濾器
- 地理位置聚合
- 地理位置聚合
- 按距離聚合
- Geohash單元聚合器
- 范圍(邊界)聚合器
- 地理形狀
- 地理形狀
- 映射地理形狀
- 索引地理形狀
- 查詢地理形狀
- 在查詢中使用已索引的形狀
- 地理形狀的過濾與緩存
- 關系
- 關系
- 應用級別的Join操作
- 扁平化你的數據
- Top hits
- Concurrency
- Concurrency solutions
- 嵌套
- 嵌套對象
- 嵌套映射
- 嵌套查詢
- 嵌套排序
- 嵌套集合
- Parent Child
- Parent child
- Indexing parent child
- Has child
- Has parent
- Children agg
- Grandparents
- Practical considerations
- Scaling
- Shard
- Overallocation
- Kagillion shards
- Capacity planning
- Replica shards
- Multiple indices
- Index per timeframe
- Index templates
- Retiring data
- Index per user
- Shared index
- Faking it
- One big user
- Scale is not infinite
- Cluster Admin
- Marvel
- Health
- Node stats
- Other stats
- Deployment
- hardware
- other
- config
- dont touch
- heap
- file descriptors
- conclusion
- cluster settings
- Post Deployment
- dynamic settings
- logging
- indexing perf
- rolling restart
- backup
- restore
- conclusion