# 映射與統(tǒng)計(jì)
當(dāng)我們?cè)谶M(jìn)行搜索的事情,我們會(huì)發(fā)現(xiàn)有一些奇怪的事情。比如有一些內(nèi)容似乎是被打破了:在我們的索引中有12條推文,中有一個(gè)包含了`2014-09-15`這個(gè)日期,但是看看下面的查詢(xún)結(jié)果中的總數(shù)量:
~~~
GET /_search?q=2014 # 12 results
GET /_search?q=2014-09-15 # 12 results !
GET /_search?q=date:2014-09-15 # 1 result
GET /_search?q=date:2014 # 0 results !
~~~
為什么我們使用字段`_all`搜索全年就會(huì)返回所有推文,而使用字段`date`搜索年份卻沒(méi)有結(jié)果呢?為什么使用兩者所得到的結(jié)果是不同的?
推測(cè)大概是因?yàn)槲覀兊臄?shù)據(jù)在`_all`和`date`在索引時(shí)沒(méi)有被相同處理。我們來(lái)看看Elasticsearch是如何處理我們的文檔結(jié)構(gòu)的。我們可以對(duì)`gb`的`tweet`使用_mapping_請(qǐng)求:
~~~
GET /gb/_mapping/tweet
~~~
我們得到:
~~~
{
"gb": {
"mappings": {
"tweet": {
"properties": {
"date": {
"type": "date",
"format": "dateOptionalTime"
},
"name": {
"type": "string"
},
"tweet": {
"type": "string"
},
"user_id": {
"type": "long"
}
}
}
}
}
}
~~~
Elasticsearch會(huì)根據(jù)系統(tǒng)自動(dòng)判斷字段類(lèi)型并生成一個(gè)映射。返回結(jié)果告訴我們`date`字段被識(shí)別成了`date`類(lèi)型。`_all`沒(méi)有出現(xiàn)是因?yàn)樗悄J(rèn)字段,但是我們知道字段`_all`實(shí)際上是`string`類(lèi)型的。
所以類(lèi)型為`date`的字段和類(lèi)型為`string`的字段的索引方式是不同的。
So fields of type `date` and fields of type `string` are indexed differently,and can thus be searched differently. That's not entirely surprising.You might expect that each of the core data types -- strings, numbers, booleansand dates -- might be indexed slightly differently. And this is true:there are slight differences.
But by far the biggest difference is actually between fields that represent_exact values_ (which can include `string` fields) and fields thatrepresent _full text_. This distinction is really important -- it's the thingthat separates a search engine from all other databases.
- Introduction
- 入門(mén)
- 初識(shí)
- 安裝
- API
- 文檔
- 索引
- 搜索
- 匯總
- 小結(jié)
- 分布式
- 本章總結(jié)
- 分布式集群
- 空集群
- 集群健康
- 添加索引
- 容錯(cuò)移轉(zhuǎn)
- 橫向擴(kuò)展
- 擴(kuò)展
- 故障恢復(fù)
- 索引
- 文檔
- Get
- 存在
- 更新
- 創(chuàng)建
- 刪除
- 版本控制
- 局部更新
- Mget
- Bulk
- 總結(jié)
- 分布式文檔存儲(chǔ)
- 路由
- 主從互通
- 創(chuàng)建索引刪除
- 獲取
- 局部更新
- 批量請(qǐng)求
- 批量格式
- 搜索
- 空白搜索
- 多索引多類(lèi)型
- 分頁(yè)
- 查詢(xún)語(yǔ)句
- 映射與統(tǒng)計(jì)
- Exact_vs_full_text
- Inverted_index
- Analysis
- Mapping
- Complex_datatypes
