ES(ElasticSearch) 索引創建

環境:ES 6.2.2

os:Centos  7

kibana:6.2.2

1、創建新的索引(index)

    PUT indexTest001

    結果:


2、索引設置

      ES 默認提供了好多索引配置選項,參考https://www.elastic.co/guide/en/elasticsearch/reference/5.6/index-modules.html,這些配置選項都有經過優化的默認配置值,除非你非常清楚這些配置的作用以及知道爲什麼去修改它,不然使用其默認值即可。

    a、分片設置

        number_of_shards
        每個索引的主分片數,默認值是 5 。這個配置在索引創建後不能修改。
        number_of_replicas

        每個主分片的副本數,默認值是 1 。對於活動的索引庫,這個配置可以隨時修改。

        例如,我們可以創建只有 一個主分片,沒有副本的小索引:
        PUT /my_test_index_004
        {
            "settings": {
            "number_of_shards" :   1,
            "number_of_replicas" : 0
            }

        }

        更改副本數量:

        PUT /my_test_index_004/_settings
        {
            "number_of_replicas": 2

        }

     每次更改分片之後可以使用:GET my_test_index_004/_search_shards 來查詢索引信息.


3、創建mapping

    a、首先查看剛剛創建的索引的mapping是什麼樣子的

        GET indextest001/_mapping

        結果:

        

         可見新建的索引中,mapping是一個空集,所以我們就要創建這個index的mapping

         命令:

        POST indextest001/product/_mapping?pretty 

    {"product":{"properties":{"title":{"type":"text","store":"true"},"description":{"type":"text","index":"false"},"price":{"type":"double"},"onSale":{"type":"boolean"},"type":{"type":"integer"},"createDate":{"type":"date"}}}}

執行完畢後再次執行上面所述查詢結果如下:


4、插入數據

POST indextest001/product
{
  "title": "test title 001",
  "description": "this is a random desc ",
  "price": 22.6,
  "onSale": "true",
  "type": 2,
  "createDate": "2018-01-12"

}

 然後查詢一下所有數據,默認爲match_all

 GET indextest001/product/

根據id查詢

 GET indextest001/product/UNBdGWIBI2NcsxokJ0lQ

 結果如下:

 

發佈了44 篇原創文章 · 獲贊 25 · 訪問量 10萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章