ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC] # 索引设置 ## 索引初始化操作 创建索引之前可以对索引做初始化操作 比如指定shards数量以及replicas的数量 ![](https://box.kancloud.cn/04fbd378e8b6ad2e38da6b2e51b3dc68_637x310.png) 如果在工具中,就这样写 ~~~ PUT http://192.168.1.121:9200/library/ { "setting": { "index": { "number_of_shards": 5, "number_of_replicas": 1 } } } # 上面的number_of_replicas还可以换成: # blocks.read_only: 设为true,则当前索引只允许读,不允许写或更新 # blocks.read : 设为true,则禁止读操作 # blocks.write: 设为true,则禁止写操作设置 # blocks.metadata: 设为true,则禁止对metadata操作 ~~~ ![](https://box.kancloud.cn/c516f1da081ccdae87924064bede1881_1424x304.png) 点了之后就不能再点了,再点就报400 ## 可以通过GET带上参数_settings可以获得该索引详细的配置信息 ~~~ GET /library/_settings ~~~ ## 同时获取2个索引信息 ~~~ GET /library,library2/_settings ~~~ ## 获取所有的索引信息 ~~~ GET /_all/_settings ~~~ # 创建索引 ![](https://box.kancloud.cn/4e8cfce64b0798820a56d82a882a2105_479x414.png) ID你可以不设置,不设置他会帮你设置一个的 ~~~ POST /library/books/ { "title": "Elasticsearch : the definitive guide", "name": { "first": "Vineeth", "last": "Mohan" }, "publish_date": "2015-02-06", "price":"35.99" } ~~~ 返回结果中有个_id的,那就是es帮你设置的 # 查询索引 ~~~ GET /library/books/1 GET /library/books/2 ~~~ 可以通过source获取指定的字段 ~~~ GET /library/books/1?_source=title,price ~~~ # 更新索引 我们更新同一个id下的文档,可以通过覆盖更新 ~~~ PUT /library/books/1 { "title": "Elasticsearch : the definitive guide", "name": { "first": "Vineeth", "last": "Mohan" }, "publish_date": "2015-02-06", "price":"25.99" } ~~~ 查询下 ~~~ GET /library/books/1 ~~~ 或者通过 `_update`这个api方式单独更新你想更新的字段 ~~~ POST /library/books/1/_update { "doc": { "price": 10 } } POST /library/books/1/_update { "doc": { "title": "fly" } } ~~~ # 删除索引 ~~~ DELETE /library/books/1 ~~~ 然后我们GET下,看下结果 发现found是false ~~~ { "_index": "library", "_type": "books", "_id": "1", "found": false } ~~~ 也可以删除type ~~~ DELETE /library/books ~~~ 也可以删除索引 ~~~ DELETE /library ~~~ # 内置字段和字段类型 ![](https://box.kancloud.cn/8c01c84a810b00fee24d0c08b902f988_1340x250.png)