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

 結果如下:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM