38.mapping小例子

來源:互聯網
上載者:User

標籤: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小例子

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.