標籤:website author mapping article 包含 word back 出現 app
主要知識點
初步瞭解mapping
一,準備資料
插入幾條資料,讓es自動為我們建立一個索引
PUT /website/article/1
{
"post_date": "2017-01-01",
"title": "my first article",
"content": "this is my first article in this website",
"author_id": 11400
}
PUT /website/article/2
{
"post_date": "2017-01-02",
"title": "my second article",
"content": "this is my second article in this website",
"author_id": 11400
}
PUT /website/article/3
{
"post_date": "2017-01-03",
"title": "my third article",
"content": "this is my third article in this website",
"author_id": 11400
}
二、嘗試各種搜尋,並比較搜尋結果
GET /website/article/_search?q=2017 3條結果
GET /website/article/_search?q=2017-01-01 3條結果
GET /website/article/_search?q=post_date:2017-01-01 1條結果
GET /website/article/_search?q=post_date:2017 1條結果
三,查看type的mapping
GET /website/_mapping/article
執行結果如下:
{
"website": {
"mappings": {
"article": {
"properties": {
"author_id": {
"type": "long"
},
"content": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"post_date": {
"type": "date"
},
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
}
由上結果可以看到es已自動為這個index下的type建立的mapping。es自動或程式員手動為index中的type建立的一種資料結構及其相關配置,簡稱為mapping。mapping分兩種:
1、dynamic mapping,自動為我們建立index,建立type,以及type對應的mapping,mapping中包含了每個field對應的資料類型,以及如何分詞等設定
2、手動建立的mapping,也可以手動在建立資料之前,先建立index和type,以及type對應的mapping。
四、搜尋結果為什麼不一致
因為es自動建立mapping的時候,為不同的field設定了不同的data type。不同的data type的分詞、搜尋等行為是不一樣的。所以出現了_all field和post_date field的搜尋表現完全不一樣。
38.mapping小例子