個人分類: ElasticSearchindex
環境: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查詢