索引库基本操作
ES 通过 Restful 请求操作索引库、文档,本文介绍如何使用 DSL 来操作索引库
创建索引库
示例模版
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| PUT /索引库名称 { "mappings":{ "properties":{ "字段1":{ "type":"text", "analyzer":"ik_smart" }, "字段2":{ "type":"keyword", "index":"false" }, "字段3":{ "properties":{ "子字段1":{ "type":long }, "子字段2":{ "type":short } } } } } }
|
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| PUT /demo_index { "mappings":{ "properties":{ "demo_property_1":{ "type":"text", "analyzer":"ik_smart" }, "demo_property_2":{ "type":"keyword", "index":"false" }, "demo_property_3":{ "properties":{ "demo_child_property_1":{ "type":"long" }, "demo_child_property_2":{ "type":"short" } } } } } }
|
查询索引库
修改索引库
在 ES 中,一般是不支持索引库的修改的,因为修改一个字段有可能会导致倒排索引失效。
虽然理论上可以去新增字段,但是在生产环境中一般也是不允许的,这种操作会对 ES 的性能带来很大的影响
1 2 3 4 5 6 7 8 9
| PUT /索引库名称/_mapping { "properties": { # 不能和已有字段重复,否则会被认为是修改,导致报错 "新字段名":{ "type":"text" } } }
|
删除索引库