怎样合理创建es索引_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

结果如下:

环境: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 结果如下:
经验分享 程序员 微信小程序 职场和发展