├── .github ├── FUNDING.yml └── workflows │ └── deploy.yml ├── .gitignore ├── README.md ├── babel.config.js ├── build.cmd ├── dev.cmd ├── docs ├── _img │ └── intellij-annotation-processors.png ├── getting_started │ ├── aggregations.md │ ├── esindex.md │ ├── getting_started.md │ ├── install.md │ ├── nextstep.md │ └── search.md ├── index_modules │ ├── analysis.md │ ├── index_blocks.md │ ├── index_modules.md │ ├── index_shard_allocation │ │ ├── data_tier_allocation_filtering.md │ │ ├── delaying_allocation.md │ │ ├── index_recovery_prioritization.md │ │ ├── index_shard_allocation.md │ │ ├── shard_allocation_filtering.md │ │ └── total_shards_per_node.md │ └── mapper.md ├── intro.md ├── intro │ ├── datain.md │ ├── inforout.md │ ├── intro.md │ └── scalability.md ├── rest_apis │ ├── api_convention │ │ ├── api_convention.md │ │ ├── common_options.md │ │ ├── cron_expressions.md │ │ ├── date_math_support_in_index_names.md │ │ ├── multi_target_syntax.md │ │ └── url-based_access_control.md │ ├── autoscaling_apis │ │ ├── autoscaling_apis.md │ │ ├── create_or_update_autoscaling_policy.md │ │ ├── delete_autoscaling_policy.md │ │ ├── get_autoscaling_capacity.md │ │ └── get_autoscaling_policy.md │ ├── behavioral_analytics_apis │ │ ├── behavioral_analytics_apis.md │ │ ├── delete_analytics_collection.md │ │ ├── list_analytics_collections.md │ │ ├── post_analytics_collection_event.md │ │ └── put-analytics-collection.md │ ├── cluster_apis │ │ └── cluster_apis.md │ ├── compact_and_aligned_text_(CAT)_apis │ │ └── compact_and_aligned_text_(CAT)_apis.md │ ├── data_stream_apis │ │ ├── create_data_stream.md │ │ ├── data_stream_apis.md │ │ ├── data_stream_stats.md │ │ ├── delete_data_stream.md │ │ ├── delete_data_stream_lifecycle.md │ │ ├── downsample.md │ │ ├── explain_data_stream_lifecycle.md │ │ ├── get_data_stream.md │ │ ├── get_data_stream_lifecycle.md │ │ ├── get_data_stream_lifecycle_state.md │ │ ├── migrate_to_data_stream.md │ │ ├── modify_data_stream.md │ │ ├── promote_data_stream.md │ │ └── put_data_stream_lifecycle.md │ ├── document_apis │ │ ├── bulk.md │ │ ├── delete.md │ │ ├── delete_by_query.md │ │ ├── docs_index.md │ │ ├── document_apis.md │ │ ├── get.md │ │ ├── multi_get.md │ │ ├── multi_termvectors.md │ │ ├── optimistic_concurrency_control.md │ │ ├── refresh.md │ │ ├── reindex.md │ │ ├── replication.md │ │ ├── termvectors.md │ │ ├── update.md │ │ └── update_by_query.md │ ├── index_apis │ │ ├── alias_exists.md │ │ ├── aliases.md │ │ ├── analyze.md │ │ ├── analyze_index_disk_usage.md │ │ ├── clear_cache.md │ │ ├── clone_index.md │ │ ├── close_index.md │ │ ├── create_index.md │ │ ├── create_or_update_component_template.md │ │ ├── create_or_update_index_alias.md │ │ ├── create_or_update_index_template.md │ │ ├── delete_component_template.md │ │ ├── delete_dangling_index.md │ │ ├── delete_index.md │ │ ├── delete_index_alias.md │ │ ├── delete_index_template.md │ │ ├── flush.md │ │ ├── force_merge.md │ │ ├── freeze_index.md │ │ ├── get_component_template.md │ │ ├── get_field_mapping.md │ │ ├── get_index.md │ │ ├── get_index_alias.md │ │ ├── get_index_settings.md │ │ ├── get_index_template.md │ │ ├── get_mapping.md │ │ ├── import_dangling_index.md │ │ ├── index_apis.md │ │ ├── index_exists.md │ │ ├── index_recovery.md │ │ ├── index_segments.md │ │ ├── index_shard_stores.md │ │ ├── index_stats.md │ │ ├── list_dangling_indices.md │ │ ├── open_index.md │ │ ├── refresh.md │ │ ├── resolve_index.md │ │ ├── rollover_index.md │ │ ├── shrink_index.md │ │ ├── simulate_index.md │ │ ├── simulate_template.md │ │ ├── split_index.md │ │ ├── synced_flush.md │ │ ├── type_exists.md │ │ ├── unfreeze_index.md │ │ ├── update_index_settings.md │ │ └── update_mapping.md │ ├── rest_apis.md │ └── search_apis │ │ ├── async_search.md │ │ ├── clear_scroll.md │ │ ├── explain.md │ │ ├── field_capabilities.md │ │ ├── knn_search.md │ │ ├── multi_search.md │ │ ├── multi_search_template.md │ │ ├── point_in_time.md │ │ ├── profile.md │ │ ├── ranking_evaluation.md │ │ ├── render_search_template.md │ │ ├── scroll.md │ │ ├── search.md │ │ ├── search_apis.md │ │ ├── search_shards.md │ │ ├── search_template.md │ │ ├── suggesters.md │ │ ├── terms_enum.md │ │ ├── validate.md │ │ └── vector_tile_search.md ├── search_your_data │ ├── search_analytics │ │ └── events_reference.md │ └── the_search_api │ │ └── search_shard_routing.md ├── set_up_elasticsearch │ ├── configuring_elasticsearch │ │ ├── auditing_settings.md │ │ ├── circuit_breaker_settings.md │ │ ├── cluster_level_shard_allocation_and_routing_settings.md │ │ ├── configuring_elasticsearch.md │ │ ├── cross_cluster_replication_settings.md │ │ ├── discovery_and_cluster_formation_settings.md │ │ ├── field_data_cache_settings.md │ │ ├── health_diagnostic_settings_in_elasticsearch.md │ │ ├── import_elasticsearch_configuration.md │ │ ├── index_lifecycle_management_settings.md │ │ ├── index_management_settings.md │ │ ├── index_recovery_settings.md │ │ ├── indexing_buffer_settings.md │ │ ├── license_settings.md │ │ ├── local_gateway_settings.md │ │ ├── logging.md │ │ ├── machine_learning_settings_in_elasticsearch.md │ │ ├── monitoring_settings_in_elasticsearch.md │ │ ├── networking.md │ │ ├── node.md │ │ └── secure_settings.md │ ├── installing_elasticsearch │ │ ├── _media │ │ │ ├── elasticsearch_exe.png │ │ │ ├── msi_installer_configuration.png │ │ │ ├── msi_installer_help.png │ │ │ ├── msi_installer_installed_service.png │ │ │ ├── msi_installer_installing.png │ │ │ ├── msi_installer_locations.png │ │ │ ├── msi_installer_selected_plugins.png │ │ │ ├── msi_installer_service.png │ │ │ ├── msi_installer_success.png │ │ │ ├── msi_installer_uninstall.png │ │ │ ├── msi_installer_upgrade_configuration.png │ │ │ ├── msi_installer_upgrade_notice.png │ │ │ ├── msi_installer_upgrade_plugins.png │ │ │ ├── msi_installer_xpack.png │ │ │ └── service-manager-win.png │ │ ├── brew.md │ │ ├── debian.md │ │ ├── docker.md │ │ ├── installing_elasticsearch.md │ │ ├── linux.md │ │ ├── msi.md │ │ ├── rpm.md │ │ └── windows.md │ └── set_up_elasticsearch.md └── vocabulary.md ├── docusaurus.config.js ├── package-lock.json ├── package.json ├── sidebars.js ├── src ├── components │ └── HomepageFeatures │ │ ├── index.js │ │ └── styles.module.css ├── css │ └── custom.css └── pages │ ├── index.module.css │ └── markdown-page.md └── static ├── .nojekyll ├── baidu_verify_codeva-8MAea7zjB5.html └── img ├── docusaurus-social-card.jpg ├── docusaurus.png ├── favicon.ico ├── logo.png ├── logo.svg ├── undraw_docusaurus_mountain.svg ├── undraw_docusaurus_react.svg └── undraw_docusaurus_tree.svg /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: https://images.bookhub.tech/mp/code.jpg 14 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Build and Deploy 2 | on: [push] 3 | jobs: 4 | build-and-deploy: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Checkout 8 | uses: actions/checkout@master 9 | - name: pwd 10 | run: pwd 11 | - name: ls 12 | run: ls 13 | - name: vuepress-deploy 14 | uses: jenkey2011/vuepress-deploy@v1.8.1 15 | env: 16 | ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }} 17 | TARGET_REPO: dev2007/elasticsearch-doc-publish 18 | TARGET_BRANCH: master 19 | BUILD_SCRIPT: npm install && npm run docs:build 20 | BUILD_DIR: docs/.vuepress/dist/ 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependencies 2 | /node_modules 3 | 4 | # Production 5 | /build 6 | 7 | # Generated files 8 | .docusaurus 9 | .cache-loader 10 | 11 | # Misc 12 | .DS_Store 13 | .env.local 14 | .env.development.local 15 | .env.test.local 16 | .env.production.local 17 | 18 | npm-debug.log* 19 | yarn-debug.log* 20 | yarn-error.log* 21 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [require.resolve('@docusaurus/core/lib/babel/preset')], 3 | }; 4 | -------------------------------------------------------------------------------- /build.cmd: -------------------------------------------------------------------------------- 1 | npm run build 2 | 3 | pause -------------------------------------------------------------------------------- /dev.cmd: -------------------------------------------------------------------------------- 1 | npm run start 2 | pause -------------------------------------------------------------------------------- /docs/_img/intellij-annotation-processors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dev2007/elasticsearch-doc/ebf9b79fda09eceac928d5ad3338d6beadc2c7bc/docs/_img/intellij-annotation-processors.png -------------------------------------------------------------------------------- /docs/getting_started/aggregations.md: -------------------------------------------------------------------------------- 1 | # 使用聚合分析结果 2 | 3 | Elasticsearch 聚合能让你获取搜索结果的元信息,并回答这些问题,如“德克萨斯州有多少账户所有者?”或“田纳西州的账户平均余额是多少?”。你可以在一个请求中搜索文档、过滤命中以及使用聚合分析结果。 4 | 5 | 例如,以下的请求使用一个词语聚合分组在银行(`bank`)索引中按州对所有账户分组,并按降序返回账户最多的十个州: 6 | 7 | ```bash 8 | GET /bank/_search 9 | { 10 | "size": 0, 11 | "aggs": { 12 | "group_by_state": { 13 | "terms": { 14 | "field": "state.keyword" 15 | } 16 | } 17 | } 18 | } 19 | ``` 20 | 21 | 响应中的桶(`bucket`)是州(`state`)字段的值。`doc_count` 显示每个州的账户数量。例如,你可以看到 ID(爱达荷州)有 27 个账户。由于这个请求设置 `size=0`,这个请求只包含聚合结果。 22 | 23 | ```json 24 | { 25 | "took": 29, 26 | "timed_out": false, 27 | "_shards": { 28 | "total": 5, 29 | "successful": 5, 30 | "skipped" : 0, 31 | "failed": 0 32 | }, 33 | "hits" : { 34 | "total" : { 35 | "value": 1000, 36 | "relation": "eq" 37 | }, 38 | "max_score" : null, 39 | "hits" : [ ] 40 | }, 41 | "aggregations" : { 42 | "group_by_state" : { 43 | "doc_count_error_upper_bound": 20, 44 | "sum_other_doc_count": 770, 45 | "buckets" : [ { 46 | "key" : "ID", 47 | "doc_count" : 27 48 | }, { 49 | "key" : "TX", 50 | "doc_count" : 27 51 | }, { 52 | "key" : "AL", 53 | "doc_count" : 25 54 | }, { 55 | "key" : "MD", 56 | "doc_count" : 25 57 | }, { 58 | "key" : "TN", 59 | "doc_count" : 23 60 | }, { 61 | "key" : "MA", 62 | "doc_count" : 21 63 | }, { 64 | "key" : "NC", 65 | "doc_count" : 21 66 | }, { 67 | "key" : "ND", 68 | "doc_count" : 21 69 | }, { 70 | "key" : "ME", 71 | "doc_count" : 20 72 | }, { 73 | "key" : "MO", 74 | "doc_count" : 20 75 | } ] 76 | } 77 | } 78 | } 79 | ``` 80 | 81 | 你可以合并聚合来构建更复杂的数据摘要。例如,以下请求在前一个按州分组(`group_by_state`)聚合嵌套一个 `avg` 聚合,以计算每个州的平均账户余额。 82 | 83 | ```bash 84 | GET /bank/_search 85 | { 86 | "size": 0, 87 | "aggs": { 88 | "group_by_state": { 89 | "terms": { 90 | "field": "state.keyword" 91 | }, 92 | "aggs": { 93 | "average_balance": { 94 | "avg": { 95 | "field": "balance" 96 | } 97 | } 98 | } 99 | } 100 | } 101 | } 102 | ``` 103 | 104 | 你可以使用嵌套聚合结果进行排序(通过指定词语聚合顺序),而不是按计数结果进行排序: 105 | 106 | ```bash 107 | GET /bank/_search 108 | { 109 | "size": 0, 110 | "aggs": { 111 | "group_by_state": { 112 | "terms": { 113 | "field": "state.keyword", 114 | "order": { 115 | "average_balance": "desc" 116 | } 117 | }, 118 | "aggs": { 119 | "average_balance": { 120 | "avg": { 121 | "field": "balance" 122 | } 123 | } 124 | } 125 | } 126 | } 127 | } 128 | ``` 129 | 130 | 除了这些基本的桶和度量聚合外,Elasticsearch 提供了特定的聚合用于操作多个字段和分析特定类型数据,如日期、IP 地址以及地理数据。你还可以将单个聚合的结果输入管道聚合用于进一步的分析。 131 | 132 | 聚合提供的核心分析能力支持高级特性,如使用机器学习来检测异常。 133 | 134 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-aggregations.html) 135 | -------------------------------------------------------------------------------- /docs/getting_started/esindex.md: -------------------------------------------------------------------------------- 1 | # 索引一些文档 2 | 3 | 一旦你有一个集群启动并运行了,你就能索引一些数据。Elasticsearch 有多种接收选项,但他们最终都做了同样的事:将 JSON 文档存入Elasticsearch 索引中。 4 | 5 | 你可以通过一个简单的 `PUT` 请求直接执行这种操作,并且在请求体中指定要添加文档的索引、唯一的文档 ID 以及一个或者多个“字段-数值”对: 6 | 7 | ```bash 8 | PUT /customer/_doc/1 9 | { 10 | "name": "John Doe" 11 | } 12 | ``` 13 | 14 | 如果 `customer` 索引还不存在,请求将自动创建它,添加一个 ID 为1的文档,并存储和索引名字字段。 15 | 16 | 由于这是一个新的文档,这个响应表明这个操作的结果为版本1的文档被创建: 17 | 18 | ```json 19 | { 20 | "_index" : "customer", 21 | "_type" : "_doc", 22 | "_id" : "1", 23 | "_version" : 1, 24 | "result" : "created", 25 | "_shards" : { 26 | "total" : 2, 27 | "successful" : 2, 28 | "failed" : 0 29 | }, 30 | "_seq_no" : 26, 31 | "_primary_term" : 4 32 | } 33 | ``` 34 | 35 | 新的文档可以从集群中的任一节点立即获得。你可以通过指定它的文档 ID 的 GET 请求来检索它: 36 | 37 | ```bash 38 | GET /customer/_doc/1 39 | ``` 40 | 41 | 响应表明指定 ID 的文档被找到,并显示了被索引的原始源字段。 42 | 43 | ```json 44 | { 45 | "_index" : "customer", 46 | "_type" : "_doc", 47 | "_id" : "1", 48 | "_version" : 1, 49 | "_seq_no" : 26, 50 | "_primary_term" : 4, 51 | "found" : true, 52 | "_source" : { 53 | "name": "John Doe" 54 | } 55 | } 56 | ``` 57 | 58 | ## 批量索引文档 59 | 60 | 如果你有大量文档要索引,你能通过`批量 API`(`bulk API`) 来批量提交它们。批量文档操作比单独提交请求显著更快,因为它极简了网络往返。 61 | 62 | 最佳的批量数量取决于许多因素:文档的大小和复杂度、索引和搜索的负载以及集群可用资源。一种好的方式是批量处理 1,000 到 5,000 个文档,且总负载在 5 MB 到 15 MB。基于这个,你能尝试找到最佳的方式。 63 | 64 | 向 Elasticsearch 导入一些数据,你就能开始搜索和分析: 65 | 66 | 1. 下载 [accounts.json](https://download.elastic.co/demos/kibana/gettingstarted/accounts.zip) 示例数据集。这个随机生成的数据集文档表示具体以下信息的用户账户: 67 | 68 | ```json 69 | { 70 | "account_number": 0, 71 | "balance": 16623, 72 | "firstname": "Bradshaw", 73 | "lastname": "Mckenzie", 74 | "age": 29, 75 | "gender": "F", 76 | "address": "244 Columbus Place", 77 | "employer": "Euron", 78 | "email": "bradshawmckenzie@euron.com", 79 | "city": "Hobucken", 80 | "state": "CO" 81 | } 82 | ``` 83 | 84 | 2. 使用以下的 `_bulk` 请求将账户数据索引到银行(`bank`) 索引中: 85 | 86 | ```bash 87 | curl -H "Content-Type: application/json" -XPOST "localhost:9200/bank/_bulk?pretty&refresh" --data-binary "@accounts.json" 88 | curl "localhost:9200/_cat/indices?v=true" 89 | ``` 90 | 91 | 响应表明 1,000 个文档被成功索引: 92 | 93 | ```bash 94 | health status index uuid pri rep docs.count docs.deleted store.size pri.store.size 95 | yellow open bank l7sSYV2cQXmu6_4rJWVIww 5 1 1000 0 128.6kb 128.6kb 96 | ``` 97 | 98 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-index.html) 99 | -------------------------------------------------------------------------------- /docs/getting_started/getting_started.md: -------------------------------------------------------------------------------- 1 | # Elasticsearch 入门 2 | 3 | 准备试用 Elasticsearch,并且看看你怎么用 REST API 去存储、搜索和分析数据? 4 | 5 | 通过本入门教程,可以: 6 | 7 | 1. 启动并运行 Elasticsearch 集群 8 | 2. 索引一些示例文档 9 | 3. 使用 Elasticsearch 查询语言搜索文档 10 | 4. 使用桶(`bucket`)和指标(`metrics`)聚合来分析结果 11 | 12 | 需要更多的背景吗? 13 | 14 | 查看[Elasticsearch 简介](/intro) 以学习术语,并理解 Elasticsearch运行的基本原理。如果你已熟悉 Elasticsearch,并且想要了解它如何与栈(Elastic Stack)的其他部分一起运行,那你可能希望跳到[Elastic Stack 教程](https://www.elastic.co/guide/en/elastic-stack-get-started/7.11/get-started-elastic-stack.html) 去了解如何使用 Elasticsearch、Kibana、Beats和Logstash 去设置系统监控方案。 15 | 16 | :::tip 注意 17 | 最快的入门 Elasticsearch 的方法是在云中[免费试用14天 Elasticsearch 服务](https://www.elastic.co/cloud/elasticsearch-service/signup?baymax=docs-body&elektra=docs)。 18 | ::: 19 | 20 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started.html) -------------------------------------------------------------------------------- /docs/getting_started/nextstep.md: -------------------------------------------------------------------------------- 1 | # 何去何从 2 | 3 | 现在你部署了一个集群,索引了一些文档以及执行了一些搜索和聚合,你可能还想: 4 | 5 | - [深入 Elastic Stack 教程](https://www.elastic.co/guide/en/elastic-stack-get-started/7.11/get-started-elastic-stack.html#install-kibana),安装 Kibana、Logstash 和 Beats,并设置一个基本的系统监控方案。 6 | 7 | - [向 Kibana 加载一个示例数据集](https://www.elastic.co/guide/en/kibana/7.11/add-sample-data.html),以了解如何将 Elasticsearch 和 Kibana 结合用以可视化数据。 8 | 9 | - 尝试 Elastic 搜索方案之一: 10 | - [网站搜索](https://swiftype.com/documentation/site-search/crawler-quick-start) 11 | - [应用搜索](https://swiftype.com/documentation/app-search/getting-started) 12 | - [企业搜索](https://swiftype.com/documentation/enterprise-search/getting-started) 13 | 14 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-next-steps.html) 15 | -------------------------------------------------------------------------------- /docs/getting_started/search.md: -------------------------------------------------------------------------------- 1 | # 开始搜索 2 | 3 | 一旦你已将一些数据存入 Elasticsearch 索引,你就能通过向 `_search` 端点发送请求来搜索它。为了获取所有的搜索能力,你可以在请求体中使用 Elasticsearch 的查询 DSL 指定搜索条件。你可以在请求 URI 中指定你想要搜索的索引名称。 4 | 5 | 例如,以下请求获取按账号排序的银行(`bank`)索引中的所有文档: 6 | 7 | ```bash 8 | GET /bank/_search 9 | { 10 | "query": { "match_all": {} }, 11 | "sort": [ 12 | { "account_number": "asc" } 13 | ] 14 | } 15 | ``` 16 | 17 | 默认情况下,响应的命中部分(`hits section`)包含符合搜索条件的前10个文档: 18 | 19 | ```json 20 | { 21 | "took" : 63, 22 | "timed_out" : false, 23 | "_shards" : { 24 | "total" : 5, 25 | "successful" : 5, 26 | "skipped" : 0, 27 | "failed" : 0 28 | }, 29 | "hits" : { 30 | "total" : { 31 | "value": 1000, 32 | "relation": "eq" 33 | }, 34 | "max_score" : null, 35 | "hits" : [ { 36 | "_index" : "bank", 37 | "_type" : "_doc", 38 | "_id" : "0", 39 | "sort": [0], 40 | "_score" : null, 41 | "_source" : {"account_number":0,"balance":16623,"firstname":"Bradshaw","lastname":"Mckenzie","age":29,"gender":"F","address":"244 Columbus Place","employer":"Euron","email":"bradshawmckenzie@euron.com","city":"Hobucken","state":"CO"} 42 | }, { 43 | "_index" : "bank", 44 | "_type" : "_doc", 45 | "_id" : "1", 46 | "sort": [1], 47 | "_score" : null, 48 | "_source" : {"account_number":1,"balance":39225,"firstname":"Amber","lastname":"Duke","age":32,"gender":"M","address":"880 Holmes Lane","employer":"Pyrami","email":"amberduke@pyrami.com","city":"Brogan","state":"IL"} 49 | }, ... 50 | ] 51 | } 52 | } 53 | ``` 54 | 55 | 这个响应也提供关于搜索请求的以下信息: 56 | 57 | - `took` —— Elasticsearch 执行查询的耗时(毫秒) 58 | - `timed_out` —— 搜索请求是否超时 59 | - `_shards` —— 多少分片被搜索,以及成功、失败或跳过的分片详情 60 | - `max_score` —— 查找到的最相关的文档分数 61 | - `hits.total.value` —— 查找到匹配文档数量 62 | - `hits.sort` —— 文档的排序位置(不按相关分数排序时) 63 | - `hits._score` —— 文档的相关分数(不适用于使用 `match_all`) 64 | 65 | 每个搜索请求都是独立的:Elasticsearch 不在请求间维护任何状态信息。在请求中指定 `from` 和 `size` 参数用来分页浏览搜索结果。 66 | 67 | 例如,以下请求获取 10 到 19 的结果: 68 | 69 | ```bash 70 | GET /bank/_search 71 | { 72 | "query": { "match_all": {} }, 73 | "sort": [ 74 | { "account_number": "asc" } 75 | ], 76 | "from": 10, 77 | "size": 10 78 | } 79 | ``` 80 | 81 | 现在你已看到如何提交基本查询请求,你可以开始构造比 `match_all` 更有趣的查询。 82 | 83 | 为了在字段中搜索指定词语,你可以使用匹配查询。例如,以下的查询搜索地址(`address`)字段,用以查找地址包含 `mill` 或 `lane`的客户: 84 | 85 | ```bash 86 | GET /bank/_search 87 | { 88 | "query": { "match": { "address": "mill lane" } } 89 | } 90 | ``` 91 | 92 | 为了执行短语搜索而不是匹配单独的词语,你可以使用 `match_phrase` 替代 `match`。例如,以下请求只匹配包含短语 `mill lane` 的地址: 93 | 94 | ```bash 95 | GET /bank/_search 96 | { 97 | "query": { "match_phrase": { "address": "mill lane" } } 98 | } 99 | ``` 100 | 101 | 为了构造更复杂的查询,你可以使用包含多个查询条件的 `bool` 的查询。你可以按必须的(必须匹配)、可选的(应该匹配)或者不必的(必须不匹配)来指定条件。 102 | 103 | 例如,以下请求搜索银行(`bank`)索引中属于 40 岁客户的账号,但排除其中住在爱达荷州(`ID`)的人: 104 | 105 | ```bash 106 | GET /bank/_search 107 | { 108 | "query": { 109 | "bool": { 110 | "must": [ 111 | { "match": { "age": "40" } } 112 | ], 113 | "must_not": [ 114 | { "match": { "state": "ID" } } 115 | ] 116 | } 117 | } 118 | } 119 | ``` 120 | 121 | 布尔查询中的每个 `must`、`should` 和 `must_not` 都称为查询子句。文档满足每个 `must` 或 `should` 条件子句的程度,有助于文档相关性的分数。分数越高,文档越符合你的搜索条件。默认情况下,Elasticsearch 返回按相关性分数排序的文档。 122 | 123 | `must_not` 子句中的条件被认作过滤器。它影响文档是否包含在结果中,但不影响文档分数。你可以显式地指定任意的过滤器,用来包含或排除基于结构化数据的文档。 124 | 125 | 例如,以下请求使用范围过滤器用以限定结果中账户余额在 $20,000 和 $30,000(含)之间。 126 | 127 | ```bash 128 | GET /bank/_search 129 | { 130 | "query": { 131 | "bool": { 132 | "must": { "match_all": {} }, 133 | "filter": { 134 | "range": { 135 | "balance": { 136 | "gte": 20000, 137 | "lte": 30000 138 | } 139 | } 140 | } 141 | } 142 | } 143 | } 144 | ``` 145 | 146 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-started-search.html) -------------------------------------------------------------------------------- /docs/index_modules/analysis.md: -------------------------------------------------------------------------------- 1 | # 分析 2 | 3 | 索引分析模块充当*分析器*的可配置注册表,它可用于将字符串字段转为独立的词语,这些词语包括: 4 | 5 | - 添加到倒排索引以使文档可搜索 6 | - 由高级查询,如[匹配查询(`match` query)](/query_dsl/full_text_queries/match)用于生成搜索词 7 | 8 | 参阅[文本分析](/text_analysis/text_analysis)获取配置详情。 9 | 10 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-analysis.html) 11 | -------------------------------------------------------------------------------- /docs/index_modules/index_blocks.md: -------------------------------------------------------------------------------- 1 | # 索引块 2 | 3 | 索引块限制对指定的索引的可用的操作类型。这些块有不同的风格,可以阻止写、读或元数据操作。块可以通过动态索引设置来设置/移除,也可以通过专用API添加,这也可以确保写入块一旦成功返回用户,所有索引分片都能正确地计算该块,例如,在添加写块后,所有对索引进行中的写入会完成。 4 | 5 | ## 索引块设置 6 | 7 | 以下的*动态*(dynamic)索引设置会影响索引上已存在的块: 8 | 9 | - `index.blocks.read_only` 10 | 11 | 设置 `true` 时,索引及索引元数据只读,`false` 允许写以及元数据变更。 12 | 13 | - `index.blocks.read_only_allow_delete` 14 | 15 | 类似于 `index.blocks.read_only`,但也允许删除索引以获取更多资源。[基于硬盘的分片分配器](/set_up_elasticsearch/configuring_elasticsearch/cluster_level_shard_allocation_and_routing_settings#基于硬盘的分片分配设置)可以自动添加和移除块。 16 | 17 | 从索引中删除文档以释放资源——而不是删除索引本身——随着时间推移会增加索引大小。当 `index.blocks.read_only_allow_delete` 设置为 `true` 时,删除索引是不允许的。然而,删除索引自身会释放只读索引块,并使资源几乎立即可用。 18 | 19 | :::caution 警告 20 | 在磁盘利用率低于高水位线时,Elasticsearch 自动添加和移除只读索引块,由 [cluster.routing.allocation.disk.watermark.flood_stage](/set_up_elasticsearch/configuring_elasticsearch/cluster_level_shard_allocation_and_routing_settings) 控制。 21 | ::: 22 | 23 | - `index.blocks.read` 24 | 25 | 设置为 `true`,可禁用对索引的读取操作。 26 | 27 | - `index.blocks.write` 28 | 29 | 设置为 `true`,可禁用对索引的数据写操作。不像 `read_only`,这个设置不会影响元数据。例如,你可以用 `write`(写)块关闭索引,但不能用 `read_only`(只读)块关闭索引。 30 | 31 | - `index.blocks.metadata` 32 | 33 | 设置为 `true`,禁用索引元数据读写。 34 | 35 | ## 添加索引块 API 36 | 37 | 为索引添加一个索引块。 38 | 39 | ```bash 40 | PUT /my-index-000001/_block/write 41 | ``` 42 | 43 | ### 请求 44 | 45 | `PUT //_block/` 46 | 47 | ### 路径参数 48 | 49 | - `` 50 | 51 | (可选,字符串)逗号分隔的列表或通配符表达式的索引名称,用于限定请求。 52 | 53 | 为所有索引添加块,使用 `_all` 或 `*`。为了禁止通过 `_all` 或通配符表达式添加块,修改集群设置 `action.destructive_requires_name` 为 `true`。你可以在文件 `elasticsearch.yml` 中修改设置,或者通过[集群更新设置](/rest_apis/cluster_apis/cluster_update_settings.html) API。 54 | 55 | - `` 56 | 57 | (必需,字符串)添加给索引的块类型。 58 | 59 | 有效值: 60 | 61 | 1. `metadata` 62 | 禁用元数据变更,比如关闭索引。 63 | 2. `read` 64 | 禁用读操作。 65 | 3. `read_only` 66 | 禁用写操作和元数据变更。 67 | 4. `write` 68 | 禁用写操作。然后,允许元数据变更。 69 | 70 | ### 查询参数 71 | 72 | - `allow_no_indices` 73 | 74 | (可选,布尔值)如果为 `false`,任何通配符、[索引别名](/rest_apis/index_apis/bulk_index_alias)或 `_all` 值只针对丢失或关闭的索引,请求将返回一个错误。即使请求以其他开启索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,而没有索引以 `bar` 开头,则以 `foo*,bar*` 为目标的请求将返回错误。 75 | 76 | 默认为 `true`。 77 | 78 | - `expand_wildcards` 79 | 80 | (可选,字符串)通配符表达式可以匹配的索引类型。如果请求可以数据流为目标,则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 `open,hidden`。有效的值有: 81 | 82 | 1. `all` 83 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 84 | 2. `open` 85 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 86 | 3. `closed` 87 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 88 | 4. `hidden` 89 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 90 | 5. `none` 91 | 不接受通配符表达式。 92 | 93 | 默认为 `open`。 94 | 95 | - `ignore_unavailable` 96 | 97 | (可选,布尔值)如果为 `true`,丢失的或关闭的索引不包含在响应中。默认为 `false`。 98 | 99 | - `master_timeout` 100 | 101 | (可选,[时间单位](/rest_apis/api_convention/common_options.html#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 102 | 103 | - `timeout` 104 | 105 | (可选,[时间单位](/rest_apis/api_convention/common_options.html#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 106 | 107 | ## 例子 108 | 109 | 以下例子展示如何添加一个索引块: 110 | 111 | ```bash 112 | PUT /my-index-000001/_block/write 113 | ``` 114 | 115 | API 返回以下响应: 116 | 117 | ```json 118 | { 119 | "acknowledged" : true, 120 | "shards_acknowledged" : true, 121 | "indices" : [ { 122 | "name" : "my-index-000001", 123 | "blocked" : true 124 | } ] 125 | } 126 | ``` 127 | 128 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-blocks.html) 129 | -------------------------------------------------------------------------------- /docs/index_modules/index_shard_allocation/data_tier_allocation_filtering.md: -------------------------------------------------------------------------------- 1 | # 索引级数据层分配过滤 2 | 3 | 你可以使用索引级别分配设置来控制将索引分配到哪个[数据层](/data_management/data_tiers)。数据层分配器是一个使用两个内置节点属性的分片分配过滤器:`_tier` 和 `_tier_preference`。 4 | 5 | 这些层属性通过这些数据角色设置: 6 | 7 | - [data_content](/set_up_elasticsearch/configuring_elasticsearch/node#内容数据节点) 8 | - [data_hot](/set_up_elasticsearch/configuring_elasticsearch/node#热数据节点) 9 | - [data_warm](/set_up_elasticsearch/configuring_elasticsearch/node#温数据节点) 10 | - [data_cold](/set_up_elasticsearch/configuring_elasticsearch/node#冷数据节点) 11 | - [data_frozen](/set_up_elasticsearch/configuring_elasticsearch/node#冻结数据节点) 12 | 13 | :::note 提示 14 | [数据](/set_up_elasticsearch/configuring_elasticsearch/node#数据节点)角色不是有效的数据层,不能用于数据层筛选。[data_frozen](/set_up_elasticsearch/configuring_elasticsearch/node#冻结数据节点) 角色只能用于搜索挂载了 shared_cache 选项的快照。 15 | ::: 16 | 17 | ## 数据层分配设置 18 | 19 | - `index.routing.allocation.include._tier` 20 | 21 | 分配索引给节点,节点的 `node.roles` 配置至少有一个逗号分隔的值。 22 | 23 | - `index.routing.allocation.require._tier` 24 | 25 | 分配索引给节点,节点的 `node.roles` 配置有所有逗号分隔的值。 26 | 27 | - `index.routing.allocation.exclude._tier` 28 | 29 | 分配索引给节点,节点的 `node.roles` 配置没有任何逗号分隔的值。 30 | 31 | - `index.routing.allocation.include._tier_preference` 32 | 33 | 分配索引给列表中具有可用节点的第一层。如果优先层中没有节点,这会阻止索引保持未分配状态。例如,如果你设置 `index.routing.allocation.include._tier_preference` 为 `data_warm,data_hot`,那么如果有节点具有 `data_warm` 角色,索引会被分配到温(warm)层。如果在温层没有节点,但有节点具有 `data_hot` 角色,索引分被分配到热(hot)层。 34 | 35 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-tier-shard-filtering.html) 36 | -------------------------------------------------------------------------------- /docs/index_modules/index_shard_allocation/delaying_allocation.md: -------------------------------------------------------------------------------- 1 | # 当节点离开时延迟分配 2 | 3 | 不论什么原因(有意还是无意)当一个节点离开集群时,主节点的反应是: 4 | 5 | - 将副本分片升级为主分片,以替换节点上的任何主分片。 6 | 7 | - 分配副本分片以替换丢失的副本(假设有足够的节点)。 8 | 9 | - 在其余节点上均匀地重新平衡分片。 10 | 11 | 这些操作旨在通过确保每个分片尽快完全复制,以保护集群避免数据丢失。 12 | 13 | 即使我们在[节点级别](/set_up_elasticsearch/configuring_elasticsearch/index_recovery_settings)和[集群级别](/set_up_elasticsearch/configuring_elasticsearch/cluster_level_shard_allocation_and_routing_settings#集群级分片分配设置)限制并发恢复,这种“分片洗牌”仍然会给集群带来大量额外负载,如果丢失的节点可能会很快返回,这可能是不必要的。想象以下场景: 14 | 15 | - 节点 5 丢失网络连接。 16 | - 对于曾是节点 5 上的主分片的副本分片,主节点将把它们提升为主分片。 17 | - 主节点将分配新的副本到集群中的其他节点。 18 | - 每个新副本通过网络生成主分片的完整复制。 19 | - 更多的分片移动到不同的节点以重平衡集群。 20 | - 节点 5 几分钟后返回。 21 | - 主节点通过分配分片到节点 5 以重平衡集群。 22 | 23 | 如果主节点仅等待了几分钟,那么丢失的分片就可以用最少的网络流量重新分配给节点 5。对于已自动[同步刷新](/rest_apis/index_apis/synced_flush)的空间分片(未接收索引请求的分片),此过程将更快。 24 | 25 | 由于一个节点已离开,副本分片分配变为未分配,可以使用 `index.unassigned.node_left.delayed_timeout` 动态设置,默认为 `1m`。 26 | 27 | 这个设置可以活动索引(或者所有索引)上更新: 28 | 29 | ```bash 30 | PUT _all/_settings 31 | { 32 | "settings": { 33 | "index.unassigned.node_left.delayed_timeout": "5m" 34 | } 35 | } 36 | ``` 37 | 38 | 如果允许延迟分配,以上的场景会变成这样: 39 | 40 | - 节点 5 丢失网络连接。 41 | - 对于曾是节点 5 上的主分片的副本分片,主节点将把它们提升为主分片。 42 | - 主节点记录日志消息,未分配的分片分配已延迟,以及延迟时长。 43 | - 集群保持黄色状态,由于存在未分配的副本分片。 44 | - 在 `timeout`(超时) 到期前,节点 5 在几分钟后返回。 45 | - 丢失的副本重新分配给节点 5(且同步刷新的分片几乎可以立即恢复)。 46 | 47 | :::note 提示 48 | 此设置不会影响将副本升级为主分片,也不会影响以前未分配副本的分配。特别是,延迟分配在集群重启后不会生效。另外,在主节点故障切换的情况下,已消耗的延迟时长会被忽视(即,重置为完全初始的延迟)。 49 | ::: 50 | 51 | ## 分片迁移取消 52 | 53 | 如果延迟分配超时,主节点分配丢失的分片到另一个节点,此节点将开始恢复。如果丢失的节点重加入集群,且它的分片仍然有与主分片相同的同步id,那么分片迁移将取消,并使用同步的分片进行恢复。 54 | 55 | 同于这个原因,默认的 `timeout`(超时)只设置为 1 分钟:即使分片迁移开始了,取消恢复而采用同步的分片也是低成本的。 56 | 57 | ## 监控延迟的未分配分片 58 | 59 | 按照超时设置延迟分配的分片数量,可以通过[集群健康 API](/rest_apis/cluster_apis/cluster_health)查看: 60 | 61 | ```bash 62 | GET _cluster/health 63 | ``` 64 | 65 | - 请求会返回 `delayed_unassigned_shards` 值。 66 | 67 | ## 永久移除节点 68 | 69 | 如果一个节点不打算返回,且你希望 Elasticsearch 立即分配丢失的分片,只需要将超时设置为 0 : 70 | 71 | ```bash 72 | PUT _all/_settings 73 | { 74 | "settings": { 75 | "index.unassigned.node_left.delayed_timeout": "0" 76 | } 77 | } 78 | ``` 79 | 80 | 一旦丢失的分片开始恢复,就可以重置超时。 81 | 82 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/delayed-allocation.html) 83 | -------------------------------------------------------------------------------- /docs/index_modules/index_shard_allocation/index_recovery_prioritization.md: -------------------------------------------------------------------------------- 1 | # 索引恢复优先级 2 | 3 | 无论何时,尽可能的按优先级顺序恢复未分析的分片。索引按优先级顺序排序,如下: 4 | 5 | - 可选的 `index.priority` 设置(先高后低) 6 | - 索引创建日期(先高后低) 7 | - 索引名字(先高后低) 8 | 9 | 这意味着,默认情况下,新索引比旧索引先恢复。 10 | 11 | 使用每个索引动态可更新的 `index.priority` 设置用于自定义索引优先级顺序。例如: 12 | 13 | ```bash 14 | PUT index_1 15 | 16 | PUT index_2 17 | 18 | PUT index_3 19 | { 20 | "settings": { 21 | "index.priority": 10 22 | } 23 | } 24 | 25 | PUT index_4 26 | { 27 | "settings": { 28 | "index.priority": 5 29 | } 30 | } 31 | ``` 32 | 33 | 在以上例子中: 34 | 35 | - `index_3` 会首先恢复,因为它有最高的 `index.priority`。 36 | - `index_4` 会接着恢复,因为它有第二高的优先级。 37 | - `index_2` 会接着恢复,因为它是最近创建的。 38 | - `index_1` 会最后恢复。 39 | 40 | 这个设置接受一个整数,也可以通过[更新索引设置 API](/rest_apis/index_apis/update_index_settings) 在活动索引中更新。 41 | 42 | ```bash 43 | PUT index_4/_settings 44 | { 45 | "index.priority": 1 46 | } 47 | ``` 48 | 49 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/recovery-prioritization.html) 50 | -------------------------------------------------------------------------------- /docs/index_modules/index_shard_allocation/index_shard_allocation.md: -------------------------------------------------------------------------------- 1 | # 索引分片分配 2 | 3 | 该模块提供每个索引设置,以控制分片分配到节点: 4 | 5 | - [分片分配过滤](/index_modules/index_shard_allocation/shard_allocation_filtering):控制将哪些分片分配给哪些节点。 6 | - [延迟分配](/index_modules/index_shard_allocation/delaying_allocation):由于节点离开而导致的未分配分片的延迟分配。 7 | - [每节点的分片总数](/index_modules/index_shard_allocation/total_shards_per_node):对每个节点来自同一索引的分片数的硬限制。 8 | - [数据层分配](/index_modules/index_shard_allocation/data_tier_allocation_filtering):控制索引到[数据层](/data_management/data_tiers)的分配。 9 | 10 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-allocation.html) 11 | -------------------------------------------------------------------------------- /docs/index_modules/index_shard_allocation/shard_allocation_filtering.md: -------------------------------------------------------------------------------- 1 | # 索引级分片分配过滤 2 | 3 | 你可以使用分片分配过滤器来控制 Elasticsearch 在何处分配特定索引的分片。每个索引过滤器与[集群范围的分配过滤](/set_up_elasticsearch/configuring_elasticsearch/cluster_level_shard_allocation_and_routing_settings#集群级分片分配过滤)和[分配感知](/set_up_elasticsearch/configuring_elasticsearch/cluster_level_shard_allocation_and_routing_settings#分片分配感知)一起应用。 4 | 5 | 分片分配过滤器可以基于自定义节点属性或内置 `_name`,`_host_ip`,`_publish_ip`,`_ip`,`_host`,`_id`,`_tier` 和 `_tier_preference` 属性。[索引生命周期管理](/ILM_manage_the_index_lifecycle)使用基于自定义节点属性的过滤器来确定在阶段之间移动时如何重分配分片。 6 | 7 | `cluster.routing.allocation` 设置是动态的,允许将活动索引从一组节点移动到另一组节点。只有在不破坏另一个路由约束的情况下(例如从不在同一节点上分配主分片和副本分片),才能重新定位分片。 8 | 9 | 例如,可以使用自定义节点属性来指示节点的性能特征,并使用分片分配过滤将特定索引的分片路由到最合适的硬件分类。 10 | 11 | ## 启用索引级分片分配过滤 12 | 13 | 为了基于自定义节点属性进行筛选: 14 | 15 | 1. 在每个节点的 `elasticsearch.yml` 配置文件中指定具有自定义节点属性过滤器特征。例如,如果你有 `small`,`medium` 和 `big` 节点,你能添加一个基于节点大小过滤的 `size` 属性。 16 | 17 | ```yaml 18 | node.attr.size: medium 19 | ``` 20 | 21 | 当你启动节点时,你也可以设置自定义属性: 22 | 23 | ```bash 24 | `./bin/elasticsearch -Enode.attr.size=medium 25 | ``` 26 | 27 | 2. 为索引添加路由分配过滤器。`index.routing.allocation` 设置支持三种过滤器:`include`、`exclude` 和 `require`。例如,要让 Elasticsearch 将测试索引中的分片分配给 `big` 或 `medium` 节点,使用 `index.routing.allocation.include`: 28 | 29 | ```bash 30 | PUT test/_settings 31 | { 32 | "index.routing.allocation.include.size": "big,medium" 33 | } 34 | ``` 35 | 36 | 如果你指定多个过滤器,则节点必须同时满足以下条件,以便分片重定位到其上: 37 | 38 | - 如果指定了任何 `require` 类型条件,则所有条件必须满足 39 | - 如果指定了任何 `exclude` 类型条件,则条件都不用满足 40 | - 如果指定了任何 `include` 类型条件,则至少有一个条件必须满足 41 | 42 | 例如,要把测试索引移动到在 `rack1` 上的 `big` 节点,你可以指定: 43 | 44 | ```bash 45 | PUT test/_settings 46 | { 47 | "index.routing.allocation.require.size": "big", 48 | "index.routing.allocation.require.rack": "rack1" 49 | } 50 | ``` 51 | 52 | ## 索引分配过滤器设置 53 | 54 | - `index.routing.allocation.include.{attribute}` 55 | 56 | 将索引分配给节点,节点的 `{attribute}` 至少有逗号分隔的一个值。 57 | 58 | - `index.routing.allocation.require.{attribute}` 59 | 60 | 将索引分配给节点,节点 `{attribute}` 具有逗号分隔的所有值。 61 | 62 | - `index.routing.allocation.exclude.{attribute}` 63 | 64 | 将索引分配给节点,节点 `{attribute}` 不具有逗号分隔的任何值。 65 | 66 | 索引分配设置支持以下的内置属性: 67 | 68 | ||| 69 | |:--|:--| 70 | |`_name`|按节点名字匹配节点| 71 | |`_host_ip`|按主机 IP 地址匹配节点(关联主机名的 IP)| 72 | |`_publish_ip`|按发布 IP 地址匹配节点| 73 | |`_ip`|匹配 `_host_ip` 或 `_publish_ip`| 74 | |`_host`|按主机名匹配节点| 75 | |`_id`|按节点 id 匹配节点| 76 | |`_tier`|按节点[数据层](/data_management/data_tiers)角色匹配节点。参阅[数据层分配过滤](/index_modules/index_shard_allocation/data_tier_allocation_filtering)获取更多详情。| 77 | 78 | 当指定属性值时,你可以使用通配符,例如: 79 | 80 | ```bash 81 | PUT test/_settings 82 | { 83 | "index.routing.allocation.include._ip": "192.168.2.*" 84 | } 85 | ``` 86 | 87 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/shard-allocation-filtering.html) 88 | -------------------------------------------------------------------------------- /docs/index_modules/index_shard_allocation/total_shards_per_node.md: -------------------------------------------------------------------------------- 1 | # 每节点分片总数 2 | 3 | 集群级分片分配器尝试将单个索引的分片分布在尽可能多的节点上。然而,根据你有多少分片和索引,以及它们有多大,可能并不总是能够均匀地分布分片。 4 | 5 | 以下的 `dynamic`(动态)设置允许你对每个节点允许的单索引的分片总数,指定硬限制: 6 | 7 | - `index.routing.allocation.total_shards_per_node` 8 | 9 | 将分配给单节点的分片(副本和主分片)最大数量。默认为无界。 10 | 11 | 你也可以限制节点可以拥有的分片数量,而不用考虑索引: 12 | 13 | - `cluster.routing.allocation.total_shards_per_node` 14 | 15 | ([动态](/set_up_elasticsearch/configuring_elasticsearch#集群和节点设置类型))分配给每个节点的主分片和副本分片的最大数量。默认值为 `-1`(无限制)。 16 | 17 | Elasticsearch 在分片分配期间检查此设置。例如,一个集群的 `cluster.routing.allocation.total_shards_per_node` 设置为 `100`,三个节点具有以下分片分配: 18 | 19 | - 节点 A: 100 分片 20 | - 节点 B: 98 分片 21 | - 节点 C: 1 分片 22 | 23 | 如果节点 C 失败,Elasticsearch 重分配它的分片到节点 B。重分配分片到节点 A 会超出 A 的分片限制。 24 | 25 | :::caution 警告 26 | 这些设置强加了一个硬限制,这可能导致一些分片不被分配。 27 | 小心使用。 28 | ::: 29 | 30 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/allocation-total-shards.html) 31 | -------------------------------------------------------------------------------- /docs/index_modules/mapper.md: -------------------------------------------------------------------------------- 1 | # 映射器 2 | 3 | 映射器模块作为在创建索引时或使用更新映射 API 时,添加到索引的类型映射定义的注册表。它还处理对没有显式映射预定义的类型的动态映射支持。获取更多有关映射定义,参阅[映射章节](/mapping/mapping)。 4 | 5 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html) 6 | -------------------------------------------------------------------------------- /docs/intro.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | slug: / 4 | --- 5 | 6 | # Elasticsearch 翻译说明 7 | 8 | 从官方版本 7.11 文档开始,当前版本为 8.13。由于官方版本更新比较快,文档虽然是基于 7.11 开始翻译,,实际翻译过程中,后续的文档都是翻译当前的最新版本。 9 | 10 | 计划在全部翻译完成后,再基于完成时的最新版本,对有差异的老版本文档进行调整。 11 | 12 | 目前翻译进度:[Read Me](https://github.com/dev2007/elasticsearch-doc#%E6%96%87%E6%A1%A3%E5%88%97%E8%A1%A8%E5%8F%8A%E8%BF%9B%E5%BA%A6) 13 | 14 | - 2024.03.29 增加搜索功能 15 | - 2023.11.08 变更文档框架为 Docusaurus 16 | 17 | ## 微信公众号 18 | 19 | 欢迎关注微信公众号:**程序员爱读书**。 20 | 21 | 分享程序员最需要的书籍和文章,助力你掌握职业生涯的方法论。 22 | 23 | ![](https://images.bookhub.tech/mp/mp_name.png) 24 | 25 | ## 感谢与支持 26 | 27 | ![license](https://img.shields.io/badge/License-CC--BY--NC-%2321BAB5) ![Translate](https://img.shields.io/badge/Translation-Elasticsearch-%2321BAB5) ![stars](https://img.shields.io/github/stars/dev2007/elasticsearch-doc?color=%2321BAB5&label=Stars&logo=github) ![forks](https://img.shields.io/github/forks/dev2007/elasticsearch-doc?color=%2321BAB5&label=Forks&logo=github) 28 | 29 | 如果对你有帮助,欢迎到 GitHub 给我一颗星星 [Star](https://github.com/dev2007/elasticsearch-doc)。 30 | 31 | 但你的赞赏比感谢更有力! 32 | 33 | 你可以花几秒关注页面上的广告,也可以请我喝咖啡,谢谢。 34 | 35 | ![code](https://images.bookhub.tech/mp/code.jpg) 36 | 37 | ### 赞赏榜 38 | 39 | > 感谢赞赏和关注广告的朋友,你们的支持可能让我继续坚持下去。 40 | 41 | |昵称|时间|赞赏|留言| 42 | |--|--|--|--| 43 | |leorn****|2024.10.30 01:16|¥10.24|--| 44 | |土豆****|2024.06.26 20:28|¥10.24|--| 45 | |o_****|2024.05.11 09:46|¥2.33|**感谢翻译**| 46 | |小f****|2024.04.03 16:25|¥2.33|--| 47 | |【未知】|2024.03.29 08:27|¥6.66|--| 48 | |【未知】|2024.03.20 09:57|¥6.66|**感谢大佬解救英语苦手**| 49 | |【未知】|2023.09.18 20:36|¥6.66|**加油**| 50 | |逃****|2023.04.15 10:43|¥0.50|--| 51 | |gr****|2022.07.17 10:22|¥6.66|--| 52 | |55****|2022.03.03 19:21|¥1.00|--| 53 | |zs****|2022.03.03 15:43|¥1.00|--| 54 | -------------------------------------------------------------------------------- /docs/intro/datain.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 10 3 | --- 4 | 5 | # 数据输入:文档和索引 6 | 7 | Elasticsearch 是一种分布式文档存储。Elasticsearch 不用列数据行存储信息,而是存储已序列化为 JSON 文档的复杂数据结构。当集群中有多个 Elasticsearch 节点时,存储的文档将分布在集群中,且可以从任何节点直接访问。 8 | 9 | 当一个文档被存储时,它会被索引并且在接近实时的1秒钟内被完全可搜索。Elasticsearch 使用一种称之为倒排索引的数据结构,支持非常快的全文搜索。倒排索引列出任何文档中出现的唯一单词,并标识每个单词出现的所有文档。 10 | 11 | 索引可被认作一种文档的优化集合,且每个文档都是字段的集合,字段是包含你数据的键值对。默认情况下,Elasticsearch 索引每个字段中的所有数据,且每个被索引的字段有一个专用的优化数据结构。例如,文本字段被存储在倒排索引中,数字和地理字段存储在 `BKD 树` 中。使用每个字段的数据结构来聚集和返回搜索结果是让 Elasticsearch 如此快的原因。 12 | 13 | Elasticsearch 也具有无模式能力,这意味着文档无需明确地指定如何处理可能出现中文档中的每个不同的字段,就可以被索引。当启用动态映射后,Elasticsearch 自动检测和向索引中添加新的字段。这个默认行为使索引和浏览你的数据更容易——只需开始索引文档,Elasticsearch 会自动检测和映射布尔值、浮点值和整数值、日期以及字符串到合适的 Elasticsearch 数据类型。 14 | 15 | 最终,然而你比 Elasticsearch 更了解你的数据以及你想如何使用它们。你能定义控制动态映射规则,而且明确的定义映射以完全控制字段如何存储和索引。 16 | 17 | 定义你自己的映射使用你能够: 18 | 19 | - 区分全文字符串字段和精确值字符串字段 20 | - 执行特定语言的文本分析 21 | - 为部分匹配优化字段 22 | - 使用自定义的日期格式 23 | - 使用无法自动检测的数据类型,如 `geo_point`和 `geo_shape` 24 | 25 | 为不同的目的以不同的方式索引相同的字段,通常是有用的。例如,你可能想索引一个字符串字段,既作为全文搜索的文本字段,也作为用于排序和聚合你的数据的关键字段。或者,你可以选择使用多个语言分析器,用来处理包含用户输入的字符串字段的内容。 26 | 27 | 用于索引期间的全文字段的分析链,也被用于搜索时。当你查询一个全文字段时,在索引中查询词语(`term`)之前,这个查询文本将经历相同的分析。 28 | 29 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/documents-indices.html) 30 | -------------------------------------------------------------------------------- /docs/intro/inforout.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 20 3 | --- 4 | 5 | # 信息输出:搜索和分析 6 | 7 | 虽然你能将 Elasticsearch用作文档存储和检测文档及他们的元数据,但真正强大之处在于能轻松访问构建在 Apache Lucene 搜索引擎库之上的全套搜索能力。 8 | 9 | Elasticsearch 提供一种简单、一致的 REST API,用于管理你的集群以及索引和搜索数据。用于测试目的,你可以轻松地从命令行或者在 Kibana 中通过开发者控制台提交请求。从你的应用里,你可以为你的语言选择 Elasticsearch 客户端:Java、JavaScript、GO、.Net、PHP、Perl、Python 或者 Ruby。 10 | 11 | ## 搜索你的数据 12 | 13 | Elasticsearch REST API 支持结构化查询、全文查询以及结合二者的复杂查询。结构化查询类似于你在 SQL 中构造的查询类型。例如,你可以在职员索引中搜索性别和年龄字段,并按雇佣日期字段对匹配项进行排序。全文查询,查找查询字符串匹配的所有文档,且返回按相关性——他们与搜索词语匹配程度——排序的文档。 14 | 15 | 除了搜索单个词语,你也可以执行短语搜索、相似性搜索和前缀搜索,并且获得自动完成建议。 16 | 17 | 有你想搜索的地理空间或者其他数字数据吗? Elasticsearch 在优化数据结构中索引非文本数据用于支持高性能地理和数字查询。 18 | 19 | 你可以访问使用 Elasticsearch 全部 JSON 风格的查询语言(查询 DSL)的所有搜索能力。你也可以构造 SQL 风格的查询搜索和聚合在 Elasticsearch 中的内部数据,JDBC 和 ODBC 驱动使得各种第三方应用能通过 SQL 与 Elasticsearch交互。 20 | 21 | ## 分析你的数据 22 | 23 | Elasticsearch 聚合使你能够构建数据的复杂摘要,并深入了解关键度量、模式和趋势。聚合使你能回答以下类似的问题,而不是仅仅找到众所周知的“大海捞针”: 24 | 25 | - 大海中有多少针? 26 | - 针的平均长度是多少? 27 | - 按制造商分类,针的平均长度是多少? 28 | - 过去六个月,每个月加了多少针? 29 | 30 | 你也可以使用聚合去回答更多微妙的问题,比如: 31 | 32 | - 你最受欢迎的针制造商是谁? 33 | - 是否有特别或者异常的针束? 34 | 35 | 因为聚合借用了用于搜索的相同数据结构,所以他们也非常快。这使得你能实时分析和可视化数据。你的报告和仪表盘随着你的数据变化而更新,以便你可以基于最新的信息采取行动。 36 | 37 | 此外,聚合随着搜索请求一起运行。你可以搜索文档、过滤结果以及在单个请求中同时对同样的数据实时地执行分析。由于聚合是在特定搜索的上下文中计算的,你不仅能展示70号针的数量,你还能展示匹配你的用户搜索标准——比如不粘的绣花针——的 70 号针数量。 38 | 39 | ## 但是等等,还有更多 40 | 41 | 想自动分析时序数据吗?你可以使用机器学习特性去创建在你数据中的正常行为的准确基线,并识别异常模式。通过机器学习,你能发现: 42 | 43 | - 与值、计数或者频率有关的时间偏差异常 44 | - 统计稀有性 45 | - 群体成员的异常行为 46 | 47 | 最好的部分呢?你可以这样做,而不必指定算法、模型或其他与科学相关的配置。 48 | 49 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-analyze.html) -------------------------------------------------------------------------------- /docs/intro/intro.md: -------------------------------------------------------------------------------- 1 | # 什么是 Elasticsearch? 2 | 3 | > 你懂的,用来搜索(也用来分析) 4 | 5 | Elasticsearch 是位于 Elastic Stack 中心的分布式搜索和分析引擎。Logstach 和 Beats 促进采集、合计以及充实你的数据并在 Elasticsearch 中存储它们。Kibana 允许你去交互式的探索、可视化和共享对数据的见解,以及监视这个栈(Elastic Stack)。Elasticsearch 是索引、搜索和分析的神奇所在。 6 | 7 | Elasticsearch 为各种数据类型提供接近实时的搜索和分析。不论你有结构化或非结构化的文本、数字数据,还是地理空间数据,Elasticsearch 能以支持快速搜索的方式高效地存储和索引它。你可以远超简单数据检索和聚合信息的方式去发现你数据中的趋势和模式。而且,随着你数据和查询量的增长,Elasticsearch 分布式的特性允许你的部署能随着它无缝地增长匹配。 8 | 9 | 虽然不是每个问题都是搜索问题,但 Elasticsearch 在大量实例中提供了处理数据的速度和灵活性: 10 | 11 | - 为应用或者网站添加搜索框 12 | - 存储和分析日志、度量和安全事件数据 13 | - 使用机器学习,实时自动建模你的数据行为 14 | - 使用 Elasticsearch 作为存储引擎来自动化业务工作流 15 | - 使用 Elasticsearch 作为地理信息系统(GIS)管理、集成和分析空间信息,以及使用 Elasticsearch 作为生物学信息研究工具处理基因数据 16 | 17 | 我们一直对人们使用搜索的新奇方式感觉惊奇。但是不论你的实例与其中一个相似,还是你正使用 Elasticsearch 来解决一个新的问题,你在 Elasticsearch处理数据、文档和索引的方式是相同的。 18 | 19 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/elasticsearch-intro.html) 20 | -------------------------------------------------------------------------------- /docs/intro/scalability.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 30 3 | --- 4 | 5 | # 可伸缩性和弹性:集群、节点和分片 6 | 7 | Elasticsearch 被构建为始终可用,并且能按需扩展。它是通过天然的分布式来实现的。你可以通过向集群添加服务器(节点)来增加容量,Elasticsearch 自动分布你的数据和查询到所有可用节点。无需改造你的应用,Elasticsearch 知道如何平衡多节点集群以提供规模和高可用性。节点越多越好。 8 | 9 | 这是如何工作的?实际来讲,一个 Elasticsearch 索引只是一个或多个物理分片的逻辑组,其中每个分片实际上是一个独立索引。通过将索引中的文档分布在多个分片上,并将这些分片分布在多个节点上,Elasticsearch 能确保冗余,这既能防止硬盘损坏也能在节点添加到集群时增加查询容量。随着集群的伸缩,Elasticsearch 自动迁移分片以重新平衡集群。 10 | 11 | 有两种类型的分片:主分片和副本。索引中的每个文档都属于一个主分片。一个副本分片是一个主分片的复制。副本提供了数据冗余复制,以防止硬件故障,并增加服务读取请求——如搜索或者检索文档——的容量。 12 | 13 | 索引中的主分片的数量是索引创建时固定的,但副本分片数量可以随时更改而不会中断索引或者查询操作。 14 | 15 | ## 看具体情况…… 16 | 17 | 对于分片大小和索引主分片数量的配置,有许多性能的考虑和权衡。分片越多,仅维护这些索引的开销就越大。分片越大,在 Elasticsearch 需要重平衡集群时,移动分片的耗时越久。 18 | 19 | 查询大量的小分片,可以让每个分片的处理更快,但更多的查询也意味着开销,所以查询更少的大分片也可能更快。简而言之……这得看情况。 20 | 21 | 作为起点: 22 | 23 | - 要保持平均分片大小在几 `GB` 到几十 `GB`。对于使用基于时间的数据用例,通常分片处于 `20 GB` 到 `40 GB` 的范围。 24 | - 避免大量分片的问题。一个节点能容纳的分片数量与可用堆空间成比例。一般来讲,每 `GB` 堆空间的分片数量应少于20。 25 | 26 | 确定你的用例的最优配置的最好方法,是[`用你自己的数据和查询进行测试`](https://www.elastic.co/cn/elasticon/conf/2016/sf/quantitative-cluster-sizing)。 27 | 28 | ## 容灾 29 | 30 | 出于性能的原因,集群中的节点需要在同一网络中。在不同数据中心平衡集群中的分片会花很长时间。但高可用的架构要求你要避免把所有鸡蛋放到一个篮子里。在一个位置发生重大停机的情况下,另一个位置的服务器需要能够无缝的接管。答案是什么呢?跨集群复制(`CCR`)。 31 | 32 | CCR 提供了一种方式自动地从主集群同步索引到作为热备的备份远程集群。如果主集群失效了,备份集群就会接管。你也可以使用 `CCR` 创建备份集群,以便在地理上靠近用户时,为读请求提供服务。 33 | 34 | 跨集群备份(`CCR`)是 `主动-被动模式`(`active-passive`)。主集群上的索引是活动的领导者索引,且处理所有写请求。复制到备份集群的索引是只读的追随者。 35 | 36 | ## 维护保养 37 | 38 | 与任何企业系统一样,你需要工具来保护、管理和监控你的 Elasticsearch 集群。集成到 Elasticsearch 中的安全、监控和管理特性使你能使用 Kibana 作为管理集群的控制中心。数据汇总和索引生命周期管理等特性可帮助你随着时间的推移智能地管理数据。 39 | 40 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/scalability.html) -------------------------------------------------------------------------------- /docs/rest_apis/api_convention/api_convention.md: -------------------------------------------------------------------------------- 1 | # API 约定 2 | 3 | Elasticsearch REST API 通过 HTTP 使用 JSON 暴露。 4 | 5 | 除非其他约定,本章列出的约定都可以用于 REST API。 6 | 7 | - [多目标语法](/rest_apis/api_convention/multi_target_syntax) 8 | - [索引名中的日期数学支持](/rest_apis/api_convention/date_math_support_in_index_names) 9 | - [Cron 表达式](/rest_apis/api_convention/cron_expressions) 10 | - [常用选项](/rest_apis/api_convention/common_options) 11 | - [基于 URL 的访问控制](/rest_apis/api_convention/url_based_access_control) 12 | -------------------------------------------------------------------------------- /docs/rest_apis/api_convention/cron_expressions.md: -------------------------------------------------------------------------------- 1 | # Cron 表达式 2 | 3 | cron 表达式是以下格式的字符串: 4 | 5 | ```bash 6 | [year] 7 | ``` 8 | 9 | Elasticsearch 使用来自 [Quartz 任务调度器](https://quartz-scheduler.org/)的 cron 解析器。有关编写 Quartz cron 表达式的更多信息,参阅 [Quartz CronTrigger 教程](http://www.quartz-scheduler.org/documentation/quartz-2.3.0/tutorials/crontrigger.html)。 10 | 11 | :::note 提示 12 | 可以使用 [elasticsearch-croneval](/command_line_tools/elasticsearch-croneval) 命令行工具校验你的 cron 表达式。 13 | ::: 14 | 15 | ## Cron 表达式元素 16 | 17 | 除了 `year`(年),所有元素都是必需的。有关允许的特殊字符的信息,参阅 [Cron 特殊字符](/rest_apis/api_convention/cron_expressions#Cron-特殊字符)。 18 | 19 | - `` 20 | (必需的) 有效值: `0`-`59` 以及特殊字符 `,` `-` `*` `/` 21 | - `` 22 | (必需的) 有效值: `0`-`59` 以及特殊字符 `,` `-` `*` `/` 23 | - `` 24 | (必需的) 有效值: `0`-`23` 以及特殊字符 `,` `-` `*` `/` 25 | - `` 26 | (必需的) 有效值: `1`-`31` 以及特殊字符 `,` `-` `*` `/` `?` `L` `W` 27 | - `` 28 | (必需的) 有效值: `1`-`12`, `JAN`-`DEC`, `jan`-`dec`, 以及特殊字符 `,` `-` `*` `/` 29 | - `` 30 | (必需的) 有效值: `1`-`7`, `SUN`-`SAT`, `sun`-`sat`, 以及特殊字符 `,` `-` `*` `/` `?` `L` `#` 31 | - `` 32 | (可选的) 有效值: `1970`-`2099` 以及特殊字符 `,` `-` `*` `/` 33 | 34 | ## Cron 特殊字符 35 | 36 | - `*` 37 | 38 | 为字段选择所有可能的值。例如,在 `hours`(小时)字段中 `*` 表示“每个小时”。 39 | 40 | - `?` 41 | 42 | 没有特定值。当你不在意值是什么时使用。例如,如果你希望计划在一个月里的特定天触发,但不关心是一周中的哪一天,你可以在 `day_of_week` 字段中指定 `?`。 43 | 44 | - `-` 45 | 46 | 范围值(包含)。用于分隔最小值和最大值。例如,如果你希望计划在上午 9:00 到下午 5:00 之间每个小时触发,你可以在 `hours` 字段指定 `9-17`。 47 | 48 | - `,` 49 | 50 | 多个值。用于字段中分隔多个值。例如,如果你希望计划在每周二和每周四触发,你可以在 `day_of_week` 字段指定 `TUE,THU`。 51 | 52 | - `/` 53 | 54 | 增量。用于当指定时间增量时分隔值。第一个值表示起点,第二个值表示间隔值。例如,如果你希望计划在一个小时里每 20 分钟触发一次,你可以在 `minutes` 字段指定 `0/20`。类似的,在 `day_of_month` 字段指定 `1/5`,将从每月的第一天开始每 5 天执行一次。 55 | 56 | - `L` 57 | 58 | 最后。在 `day_of_month` 字段中使用,意味着这个月的最后一天——1 月时是 31 日,不闰年时 2 月时是 28 日,4 月时是 30 日,等等。在 `day_of_week` 字段中单独使用以替代 `7` 或 `SAT`,或者在一周中的某一特定日期后,选择该类型在月中最后一天。例如,`6L` 代表一个月的最后一个周五。你可以在 `day_of_month` 字段指定 `LW`,用于指定该月的最后一个工作日。当指定值的列表或范围时,避免使用 `L` 选项,因为结果可能不是你期待的结果。 59 | 60 | - `W` 61 | 62 | 工作日。用于指定靠近指定日期的工作日(星期一到星期五)。例如,如果你在 `day_of_month` 字段指定 `15W`,且 15 号是星期六,计划将在 14 号触发。如果 15 号是星期天,计划将在 16 号星期一触发。如果 15 号是星期二,计划会在 15 号星期二触发。然而,如果你为 `day_of_month` 指定 `1W`,且 1 号是星期六,计划会在 3 号星期一触发——它不会跳过月的范围。你可以在 `day_of_month` 字段指定 `LW`,用于指定一个月的最后一个工作日。当 `day_of_month` 是单独的一天,你才能使用 `W` 选项——当指定的是一个范围或列表天数时,它是无效的。 63 | 64 | - `#` 65 | 66 | 一个月里的第XXX天。在 `day_of_week` 字段用于指定一个月的第XXX天。例如,如果你指定 `6#1`,计划会在一个月的第一个星期五触发。注意你指定 `3#5`,且在某一个月里没有 5 个星期二,计划在那个月不会触发。 67 | 68 | ## 例子 69 | 70 | ### 设置每日触发器 71 | 72 | - `0 5 9 * * ?` 73 | 74 | 在每天上午 UTC 9:05 触发。 75 | 76 | - `0 5 9 * * ? 2020` 77 | 78 | 在 2020 年的每天上午 UTC 9:05 触发。 79 | 80 | ### 限制触发器为天数或时间范围 81 | 82 | - `0 5 9 ? * MON-FRI` 83 | 84 | 在星期一到星期五的每天上午 UTC 9:05 触发。 85 | 86 | - `0 0-5 9 * * ?` 87 | 88 | 在每天上午 9:00 UTC 到 9:05 UTC 的每分钟触发。 89 | 90 | ### 设置周期触发器 91 | 92 | - `0 0/15 9 * * ?` 93 | 94 | 在每天上午 9:00 UTC 到 9:45 UTC 每 15 分钟触发。 95 | 96 | - `0 5 9 1/3 * ?` 97 | 98 | 从一个月的第一天开始,每 3 天在上午 9:05 UTC 触发。 99 | 100 | ### 设置特定日期触发的计划 101 | 102 | - `0 1 4 1 4 ?` 103 | 104 | 在 4 月 1 日上午 4:01 UTC 触发。 105 | 106 | - `0 0,30 9 ? 4 WED` 107 | 108 | 在 4 月的每个星期三的上午 9:00 UTC 和 9:30 UTC 触发。 109 | 110 | - `0 5 9 15 * ?` 111 | 112 | 在每个月 15 号的上午 9:05 UTC 触发。 113 | 114 | - `0 5 9 15W * ?` 115 | 116 | 在每个月的 15 号最近的工作日的上午 9:05 UTC 触发。 117 | 118 | - `0 5 9 ? * 6#1` 119 | 120 | 在每个月的第一个星期一的上午 9:05 UTC 触发。 121 | 122 | ### 使用 last(最后)设置触发器 123 | 124 | - `0 5 9 L * ?` 125 | 126 | 在每个月的最后一天的上午 9:05 UTC 触发。 127 | 128 | - `0 5 9 ? * 2L` 129 | 130 | 在每个月的最后一个星期一的上午 9:05 UTC 触发。 131 | 132 | - `0 5 9 LW * ?` 133 | 134 | 在每个月的最后一个工作日的上午 9:05 UTC 触发。 135 | 136 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/cron-expressions.html) 137 | -------------------------------------------------------------------------------- /docs/rest_apis/api_convention/date_math_support_in_index_names.md: -------------------------------------------------------------------------------- 1 | # 索引名中的日期数学支持 2 | 3 | 日期数学索引名字解析允许你搜索一系列时序索引,而不是搜索所有时序索引并过滤结果或维护别名。限制搜索的索引数可以减少集群上的负载并改进执行性能。例如,如果你在每日日志中搜索错误,你可以使用日期数学名字模板来限制搜索为过去两天。 4 | 5 | 几乎所有具有 `index`(索引)参数的 API,都支持 `index`(索引)参数值中的日期数学。 6 | 7 | 日期数学索引名字采用以下形式: 8 | 9 | ```bash 10 | 11 | ``` 12 | 13 | 其中: 14 | 15 | ||| 16 | |:--|:--| 17 | |`static_name`|名字的静态文字部分| 18 | |`date_math_expr`|动态计算日期的动态日期数学表达式| 19 | |`date_format`|显示计算日期的可选格式。默认为 `yyyy.MM.dd`。格式应与 java-time 兼容。[https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html)| 20 | |`time_zone`|可选的时区。默认为 `utc`。| 21 | 22 | :::note 提示 23 | `date_format`(日期格式)中使用的大小写字母。例如,`mm` 表示分钟,`MM`表示月份。类似的,`hh` 表示 `1-12` 范围内的小时,与 `AM/PM` 组合使用,而 `HH` 表示 `0-23` 24小时范围内的小时。 24 | ::: 25 | 26 | 日期数学表达式与区域无关。因此,不以使用格列高利历之外的日历。 27 | 28 | 必须将日期数学索引名字表达式包在尖括号内,并且所有特殊字符都应进行 URI 编码。例如: 29 | 30 | ```bash 31 | # PUT / 32 | PUT /%3Cmy-index-%7Bnow%2Fd%7D%3E 33 | ``` 34 | 35 | :::note 提示 36 | 日期数学字符的百分比编码 37 | 日期格式特定字符必须为 URI 编码,如下: 38 | 39 | ||| 40 | |:--|:--| 41 | |<|%3C| 42 | |>|%3E| 43 | |/|%2F| 44 | |{|%7B| 45 | |}|%7D| 46 | |||%7C| 47 | |+|%2B| 48 | |:|%3A| 49 | |,|%2C| 50 | ::: 51 | 52 | 以下示例显示日期数学索引名字的不同格式,且给定当前时间为 UTC 2024年3月22日中午,它们解析为最终索引名字。 53 | 54 | |表达式|解析为| 55 | |:--|:--| 56 | ||logstash-2024.03.22| 57 | ||logstash-2024.03.01| 58 | ||logstash-2024.03| 59 | ||logstash-2024.02| 60 | ||logstash-2024.03.23| 61 | 62 | 为了在索引名字模板的静态部分中使用字符 { 和 },请使用反斜杠 \ 转义,例如: 63 | 64 | - `` 解析为 `elastic{ON}-2024.03.01` 65 | 66 | 以下例子展示了一个搜索请求,该请求搜索过去三天的 Logstash 索引,假设索引使用默认的 Logstash 索引名字格式 `logstash-yyyy.MM.dd`。 67 | 68 | ```bash 69 | # GET /,,/_search 70 | GET /%3Clogstash-%7Bnow%2Fd-2d%7D%3E%2C%3Clogstash-%7Bnow%2Fd-1d%7D%3E%2C%3Clogstash-%7Bnow%2Fd%7D%3E/_search 71 | { 72 | "query" : { 73 | "match": { 74 | "test": "data" 75 | } 76 | } 77 | } 78 | ``` 79 | 80 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html) 81 | -------------------------------------------------------------------------------- /docs/rest_apis/api_convention/multi_target_syntax.md: -------------------------------------------------------------------------------- 1 | # 多目标语法 2 | 3 | 大多数 API 接受 ``、`` 或 `` 请求路径参数,也支持多目标语法。 4 | 5 | 在多目标语法中,你可以使用逗号分隔的列表在多个资源上运行请求,比如数据流、索引或者[索引别名](/rest_apis/bulk_index_alias):`test1,test2,test3`。你还可以使用类似 [glob](https://en.wikipedia.org/wiki/Glob_(programming)) 的通配符(*)表达式匹配模式为:`test*` 或 `*test` 或 `te*t` 或 `*test*.` 的目标资源。 6 | 7 | 你可以使用 `-` 字符排除目标:`test*,-test3`。 8 | 9 | :::caution 警告 10 | 索引别名在通配符表达式后解析。这可能导致以排除的别名为目标的请求。例如,如果 `test3` 是一个索引别名,这个模式 `test*`,`-test3` 仍然以 `test3` 的索引为目标。要避免这种情况,排除别名的具体索引。 11 | ::: 12 | 13 | 针对索引的多目标 API,支持以下的查询字符串参数: 14 | 15 | - `ignore_unavailable` 16 | 17 | (可选,布尔值)如果为 `true`,缺失或者关闭的索引不包含在响应中。默认值为 `false`。 18 | 19 | - `allow_no_indices` 20 | 21 | (可选,布尔值)如果为 `false`,任何通配符表达式、索引别名或 `_all` 值只针对缺失或者关闭的索引,则请求将返回错误。即使请求以其他开放索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,同时没有索引以 `bar` 开头,则一个以 `foo*,bar*`为目标的请求会返回错误。 22 | 23 | - `expand_wildcards` 24 | 25 | (可选,字符串)通配符表达式可以匹配的索引类型。如果请求可以以数据流为目标,则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 `open,hidden`。有效值为: 26 | 27 | - `all` 28 | 29 | 匹配任何数据流或索引,包括[隐藏的](/rest_apis/api_conventions/multi_target_syntax#隐藏数据流和索引)。 30 | 31 | - `open` 32 | 33 | 匹配开启的、非隐藏的索引。也匹配任何非隐藏的数据流。 34 | 35 | - `closed` 36 | 37 | 匹配关闭的、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能被关闭。 38 | 39 | - `hidden` 40 | 41 | 匹配隐藏的数据流和隐藏的索引。必须与 `open`、`closed` 或一并结合使用。 42 | 43 | - `none` 44 | 45 | 不接受通配符表达式。 46 | 47 | 上述参数的默认设置取决于所使用的 API。 48 | 49 | 一些针对索引的多目标 API,还支持以下查询字符串参数: 50 | 51 | - `ignore_throttled` 52 | 53 | (可选,布尔值)如果为 `true`,具体、展开或别名索引在冻结时将忽略。默认值为 `true`。 54 | 55 | :::note 提示 56 | 单索引 API,如[文档 API](/rest_apis/document_apis)和[单索引别名 API](/rest_apis/index_apis/bulk_index_alias),不支持多目标语法。 57 | ::: 58 | 59 | ## 隐藏数据流和索引 60 | 61 | 对大多数 API,默认通配符表达式不匹配隐藏的数据流和索引。为了使用通配符表达式匹配隐藏数据流和索引,你必须指定 `expand_wildcards` 查询参数。 62 | 63 | 你可以通过在数据流匹配索引模板中设置 [`data_stream.hidden`](/rest_apis/index_apis/create_or_update_index_template#请求体) 为 `true` 来创建隐藏数据流。你可以使用 [`index.hidden`](/index_modules#静态索引设置) 索引设置来隐藏索引。 64 | 65 | 数据流的备份索引将自动隐藏。一些特性,如机器学习,信息将存储在隐藏索引中。 66 | 67 | 匹配所有索引的全局索引模板不会应用于隐藏索引。 68 | 69 | ## 系统索引 70 | 71 | Elasticsearch 模块和插件可以在内部系统索引中存储配置和状态信息。你不应该直接访问或修改系统索引,因为它们包含系统运行所必需的数据。 72 | 73 | :::caution 警告 74 | 不推荐直接访问系统索引,并且在下一个主要版本中将不再允许直接访问系统索引。 75 | ::: 76 | 77 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/7.11/multi-index.html) 78 | -------------------------------------------------------------------------------- /docs/rest_apis/api_convention/url-based_access_control.md: -------------------------------------------------------------------------------- 1 | # 基于 URL 的访问控制 2 | 3 | 许多用户使用基于 URL 的访问控制的代理来保护对 Elasticsearch 数据流和索引的访问。对[多搜索](/rest_apis/search_apis/multi_search)、[多获取](/rest_apis/document_apis/multi_get)和[批量](/rest_apis/document_apis/bulk)请求,用户可以选择在 URL 和带请求体的每个独立请求中指定数据流或索引。这会使基于 URL 的访问控制具有挑战性。 4 | 5 | 为了阻止用户重写在 URL 中指定的数据流或索引,在 `elasticsearch.yml` 中设置 `rest.action.multi.allow_explicit_index` 为 `false`。 6 | 7 | 这可以引起 Elasticsearch 拒绝在请求体中显示指定数据流或索引的请求。 8 | 9 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/url-access-control.html) 10 | -------------------------------------------------------------------------------- /docs/rest_apis/autoscaling_apis/autoscaling_apis.md: -------------------------------------------------------------------------------- 1 | # 自动伸缩 API 2 | 3 | :::note 提示 4 | 此特性设计用于 [Elasticsearch Service](https://www.elastic.co/cloud/elasticsearch-service/signup?baymax=docs-body&elektra=docs)、[Elastic Cloud Enterprise](https://www.elastic.co/guide/en/cloud-enterprise/current) 和 [Kubernetes 上的 Elastic Cloud](https://www.elastic.co/guide/en/cloud-on-k8s/current) 的间接使用。不支持直接用户使用。 5 | ::: 6 | 7 | ## 顶级 8 | 9 | - [获取自动伸缩容量](/rest_apis/autoscaling_apis/get_autoscaling_capacity) 10 | - [创建或更新自动伸缩策略](/rest_apis/autoscaling_apis/create_or_update_autoscaling_policy) 11 | - [删除自动伸缩策略](/rest_apis/autoscaling_apis/delete_autoscaling_policy) 12 | - [获取自动伸缩策略](/rest_apis/autoscaling_apis/get_autoscaling_policy) 13 | 14 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/autoscaling-apis.html) 15 | -------------------------------------------------------------------------------- /docs/rest_apis/autoscaling_apis/create_or_update_autoscaling_policy.md: -------------------------------------------------------------------------------- 1 | # 创建或更新自动伸缩策略 API 2 | 3 | :::note 提示 4 | 此特性设计用于 [Elasticsearch Service](https://www.elastic.co/cloud/elasticsearch-service/signup?baymax=docs-body&elektra=docs)、[Elastic Cloud Enterprise](https://www.elastic.co/guide/en/cloud-enterprise/current) 和 [Kubernetes 上的 Elastic Cloud](https://www.elastic.co/guide/en/cloud-on-k8s/current) 的间接使用。不支持直接用户使用。 5 | ::: 6 | 7 | 创建或更新一个自动伸缩策略。 8 | 9 | ## 请求 10 | 11 | ```bash 12 | PUT /_autoscaling/policy/ 13 | { 14 | "roles": [], 15 | "deciders": { 16 | "fixed": { 17 | } 18 | } 19 | } 20 | ``` 21 | 22 | ## 前置条件 23 | 24 | - 如果 Elasticsearch 安全特性启用,你必须有 `manage_autoscaling` [集群权限](/secure_the_elastic_statck/user_authorization/security_privileges.html#集群权限)来使用此 API。 25 | 26 | - 如果启用了[操作员权限特性](/secure_the_elastic_stack/operator_privileges/operator_privileges),则只有操作员用户可以使用此 API。 27 | 28 | ## 描述 29 | 30 | 此 API 使用提供的名称修改自动伸缩策略。关于可用的决策器,参阅[自动伸缩决策器](/autoscaling/autoscaling_deciders)。 31 | 32 | ## 示例 33 | 34 | 此示例使用固定的自动缩放决策器,将名为 `my_autoscaling_policy` 的自动缩放策略应用于(仅)具有 “data_hot” 角色的节点集。 35 | 36 | ```bash 37 | PUT /_autoscaling/policy/my_autoscaling_policy 38 | { 39 | "roles" : [ "data_hot" ], 40 | "deciders": { 41 | "fixed": { 42 | } 43 | } 44 | } 45 | ``` 46 | 47 | 此 API 返回以下结果: 48 | 49 | ```bash 50 | { 51 | "acknowledged": true 52 | } 53 | ``` 54 | 55 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/autoscaling-put-autoscaling-policy.html) 56 | -------------------------------------------------------------------------------- /docs/rest_apis/autoscaling_apis/delete_autoscaling_policy.md: -------------------------------------------------------------------------------- 1 | # 删除自动伸缩策略 API 2 | 3 | :::note 提示 4 | 此特性设计用于 [Elasticsearch Service](https://www.elastic.co/cloud/elasticsearch-service/signup?baymax=docs-body&elektra=docs)、[Elastic Cloud Enterprise](https://www.elastic.co/guide/en/cloud-enterprise/current) 和 [Kubernetes 上的 Elastic Cloud](https://www.elastic.co/guide/en/cloud-on-k8s/current) 的间接使用。不支持直接用户使用。 5 | ::: 6 | 7 | 删除自动伸缩策略。 8 | 9 | ## 请求 10 | 11 | ```bash 12 | DELETE /_autoscaling/policy/ 13 | ``` 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你必须有 `manage_autoscaling` [集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)来使用此 API。 18 | 19 | - 如果启用了[操作员权限特性](/secure_the_elastic_stack/operator_privileges/operator_privileges),则只有操作员用户可以使用此 API。 20 | 21 | ## 描述 22 | 23 | 此 API 使用提供的名称删除一个自动伸缩策略。 24 | 25 | ## 示例 26 | 27 | 此示例删除一个名为 `my_autoscaling_policy` 的 自动伸缩策略。 28 | 29 | ```bash 30 | DELETE /_autoscaling/policy/my_autoscaling_policy 31 | ``` 32 | 33 | 此 API 返回以下结果: 34 | 35 | ```bash 36 | { 37 | "acknowledged": true 38 | } 39 | ``` 40 | 41 | 此示例删除所有自动伸缩策略。 42 | 43 | ```bash 44 | DELETE /_autoscaling/policy/* 45 | ``` 46 | 47 | 此 API 返回以下结果: 48 | 49 | ```bash 50 | { 51 | "acknowledged": true 52 | } 53 | ``` 54 | 55 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/autoscaling-delete-autoscaling-policy.html) 56 | -------------------------------------------------------------------------------- /docs/rest_apis/autoscaling_apis/get_autoscaling_policy.md: -------------------------------------------------------------------------------- 1 | # 获取自动伸缩策略 API 2 | 3 | :::note 提示 4 | 此特性设计用于 [Elasticsearch Service](https://www.elastic.co/cloud/elasticsearch-service/signup?baymax=docs-body&elektra=docs)、[Elastic Cloud Enterprise](https://www.elastic.co/guide/en/cloud-enterprise/current) 和 [Kubernetes 上的 Elastic Cloud](https://www.elastic.co/guide/en/cloud-on-k8s/current) 的间接使用。不支持直接用户使用。 5 | ::: 6 | 7 | ## 请求 8 | 9 | ```bash 10 | GET /_autoscaling/policy/ 11 | ``` 12 | 13 | ## 前置条件 14 | 15 | - 如果 Elasticsearch 安全特性启用,你必须有 `manage_autoscaling` 集群权限。更多信息,参阅[安全权限](/secure_the_elastic_statck/user_authorization/security_privileges)。 16 | 17 | ## 描述 18 | 19 | 此 API 获取指定名字的自动伸缩策略。 20 | 21 | ## 示例 22 | 23 | 此示例获取名为 `my_autoscaling_policy` 自动伸缩策略。 24 | 25 | ```bash 26 | GET /_autoscaling/policy/my_autoscaling_policy 27 | ``` 28 | 29 | 此 API 返回以下结果: 30 | 31 | ```bash 32 | { 33 | "roles": , 34 | "deciders": 35 | } 36 | ``` 37 | 38 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/autoscaling-get-autoscaling-policy.html) 39 | -------------------------------------------------------------------------------- /docs/rest_apis/behavioral_analytics_apis/behavioral_analytics_apis.md: -------------------------------------------------------------------------------- 1 | # 行为分析 API 2 | 3 | :::caution 警告 4 | 此功能为测试版,可能会有更改。其设计和代码不如 GA 正式功能成熟,因此不提供任何保证。测试版功能不受 GA 正式功能的支持服务级别协议约束。 5 | ::: 6 | 7 | 使用以下 API 管理与行为分析相关的任务和资源: 8 | 9 | - [放入分析集合](/rest_apis/behavioral_analytics_apis/put-analytics-collection) 10 | - [删除分析集合](/rest_apis/behavioral_analytics_apis/delete_analytics_collection) 11 | - [列出分析集合](/rest_apis/behavioral_analytics_apis/list_analytics_collections) 12 | 13 | 使用以下 API 将事件纳入分析集合: 14 | 15 | - [发布分析收集事件](/rest_apis/behavioral_analytics_apis/post_analytics_collection_event) 16 | 17 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/behavioral-analytics-apis.html) 18 | -------------------------------------------------------------------------------- /docs/rest_apis/behavioral_analytics_apis/delete_analytics_collection.md: -------------------------------------------------------------------------------- 1 | # 删除分析集合 2 | 3 | :::caution 警告 4 | 此功能为测试版,可能会有更改。其设计和代码不如 GA 正式功能成熟,因此不提供任何保证。测试版功能不受 GA 正式功能的支持服务级别协议约束。 5 | ::: 6 | 7 | 删除分析集合及其相关数据流。 8 | 9 | ## 请求 10 | 11 | `DELETE _application/analytics/` 12 | 13 | ## 前置条件 14 | 15 | 需要 `manage_behavioral_analytics` 集群权限。 16 | 17 | ## 路径参数 18 | 19 | - `` 20 | (必需,字符串) 21 | 22 | ## 响应码 23 | 24 | - `400` 25 | `name` 未提供 26 | 27 | - `404` (缺失资源) 28 | 未找到与 `name` 匹配的分析数据集。 29 | 30 | ## 示例 31 | 32 | 下面的示例将删除名为 `my_analytics_collection` 的分析集合。 33 | 34 | ```bash 35 | DELETE _application/analytics/my_analytics_collection/ 36 | ``` 37 | 38 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-analytics-collection.html) 39 | -------------------------------------------------------------------------------- /docs/rest_apis/behavioral_analytics_apis/list_analytics_collections.md: -------------------------------------------------------------------------------- 1 | # 列出分析集合 2 | 3 | :::caution 警告 4 | 此功能为测试版,可能会有更改。其设计和代码不如 GA 正式功能成熟,因此不提供任何保证。测试版功能不受 GA 正式功能的支持服务级别协议约束。 5 | ::: 6 | 7 | ## 请求 8 | 9 | `GET _application/analytics/` 10 | 11 | ## 前置条件 12 | 13 | 需要获得 `manage_behavioral_analytics` 集群权限。 14 | 15 | ## 路径参数 16 | 17 | - `` 18 | (可选,字符串)标准用于查找匹配的分析集合。可以是集合名称,也可以是匹配多个集合的模式。如果未指定,将返回所有分析集合。 19 | 20 | ## 响应码 21 | 22 | - `404` 23 | 标准与任何分析集合不匹配。 24 | 25 | ## 示例 26 | 27 | 下面的示例列出了所有已配置的分析集合: 28 | 29 | ```bash 30 | GET _application/analytics/ 31 | ``` 32 | 33 | 一个示例响应: 34 | 35 | ```json 36 | { 37 | "my_analytics_collection": { 38 | "event_data_stream": { 39 | "name": "behavioral_analytics-events-my_analytics_collection" 40 | } 41 | }, 42 | "my_analytics_collection2": { 43 | "event_data_stream": { 44 | "name": "behavioral_analytics-events-my_analytics_collection2" 45 | } 46 | } 47 | } 48 | ``` 49 | 50 | 下面的示例会返回与 `my_analytics_collection` 匹配的分析集合: 51 | 52 | ```bash 53 | GET _application/analytics/my_analytics_collection 54 | ``` 55 | 56 | 一个示例响应: 57 | 58 | ```json 59 | { 60 | "my_analytics_collection": { 61 | "event_data_stream": { 62 | "name": "behavioral_analytics-events-my_analytics_collection" 63 | } 64 | } 65 | } 66 | ``` 67 | 68 | 下面的示例会返回所有以 `my` 为前缀的分析集合: 69 | 70 | ```bash 71 | GET _application/analytics/my* 72 | ``` 73 | 74 | 一个示例响应: 75 | 76 | ```json 77 | { 78 | "my_analytics_collection": { 79 | "event_data_stream": { 80 | "name": "behavioral_analytics-events-my_analytics_collection" 81 | } 82 | }, 83 | "my_analytics_collection2": { 84 | "event_data_stream": { 85 | "name": "behavioral_analytics-events-my_analytics_collection2" 86 | } 87 | } 88 | } 89 | ``` 90 | 91 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/list-analytics-collection.html) 92 | -------------------------------------------------------------------------------- /docs/rest_apis/behavioral_analytics_apis/post_analytics_collection_event.md: -------------------------------------------------------------------------------- 1 | # 将事件发布到分析集合 2 | 3 | :::caution 警告 4 | 此功能为测试版,可能会有更改。其设计和代码不如 GA 正式功能成熟,因此不提供任何保证。测试版功能不受 GA 正式功能的支持服务级别协议约束。 5 | ::: 6 | 7 | 将事件发布到分析集合。 8 | 9 | ## 请求 10 | 11 | `POST _application/analytics//event/` 12 | 13 | ## 路径参数 14 | 15 | - `` 16 | (必填,字符串)您要在其中摄取事件的分析集合名称。 17 | 18 | - `` 19 | (必填,字符串)分析事件类型。可以是 `page_view`、`search`、`search_click` 中的一种。 20 | 21 | ## 请求体 22 | 23 | 完整的请求体参数可在此找到:[事件参考](/search_your_data/search_analytics/events_reference)。 24 | 25 | ## 前置条件 26 | 27 | 需要获得 `manage_behavioral_analytics` 集群权限。 28 | 29 | ## 响应码 30 | 31 | - `202` 32 | 事件已被接受并将被输入。 33 | 34 | - `404` 35 | 分析集合 `` 不存在。 36 | 37 | - `400` 38 | 事件类型未知或事件有效负载包含无效数据时出现。 39 | 40 | ## 示例 41 | 42 | 下面的示例将 `search_click` 事件发送到名为 `my_analytics_collection` 的分析集合。 43 | 44 | ```bash 45 | POST _application/analytics/my_analytics_collection/event/search_click 46 | { 47 | "session": { 48 | "id": "1797ca95-91c9-4e2e-b1bd-9c38e6f386a9" 49 | }, 50 | "user": { 51 | "id": "5f26f01a-bbee-4202-9298-81261067abbd" 52 | }, 53 | "search":{ 54 | "query": "search term", 55 | "results": { 56 | "items": [ 57 | { 58 | "document": { 59 | "id": "123", 60 | "index": "products" 61 | } 62 | } 63 | ], 64 | "total_results": 10 65 | }, 66 | "sort": { 67 | "name": "relevance" 68 | }, 69 | "search_application": "website" 70 | }, 71 | "document":{ 72 | "id": "123", 73 | "index": "products" 74 | } 75 | } 76 | ``` 77 | 78 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/post-analytics-collection-event.html) 79 | -------------------------------------------------------------------------------- /docs/rest_apis/behavioral_analytics_apis/put-analytics-collection.md: -------------------------------------------------------------------------------- 1 | # 创建分析集合 2 | 3 | :::caution 警告 4 | 此功能为测试版,可能会有更改。其设计和代码不如 GA 正式功能成熟,因此不提供任何保证。测试版功能不受 GA 正式功能的支持服务级别协议约束。 5 | ::: 6 | 7 | 创建分析集合。 8 | 9 | ## 请求 10 | 11 | `PUT _application/analytics/` 12 | 13 | ## 路径参数 14 | 15 | - `` 16 | (必填,字符串) 17 | 18 | ## 前提条件 19 | 20 | 需要 `manage_behavioral_analytics` 集群权限。 21 | 22 | ## 响应码 23 | 24 | - `400` 25 | 分析集合 `` 存在。 26 | 27 | ## 示例 28 | 29 | 下面的示例创建了一个新的分析集合,名为:`my_analytics_collection`: 30 | 31 | ```bash 32 | PUT _application/analytics/my_analytics_collection 33 | ``` 34 | 35 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/put-analytics-collection.html#put-analytics-collection) 36 | -------------------------------------------------------------------------------- /docs/rest_apis/cluster_apis/cluster_apis.md: -------------------------------------------------------------------------------- 1 | # 集群 API 2 | 3 | :::info 新 API 参考 4 | 有关最新 API 的详细信息,参阅[集群 API](https://www.elastic.co/docs/api/doc/elasticsearch/v8/group/endpoint-cluster)。 5 | ::: 6 | 7 | ## 节点规范 8 | 9 | 某些集群级 API 可在节点子集上运行,这些节点子集可通过*节点过滤器*指定。例如,[任务管理](./task_management)、[节点统计](./cluster_stats) 和 [节点信息](./nodes_info) API 都可以报告经过筛选的节点集而非全部节点的结果。 10 | 11 | *节点过滤器*是以逗号分隔的单个过滤器列表形式编写的,每个过滤器都可从所选子集中添加或删除节点。每个过滤器可以是以下其中之一: 12 | 13 | - `_all`,将所有节点添加到子集中。 14 | - `_local`,将本地节点添加到子集中。 15 | - `_master`,将当前选中的主节点加入子集。 16 | - 节点 ID 或名称,将该节点添加到子集中。 17 | - IP 地址或主机名,将所有匹配的节点添加到子集中。 18 | - 模式,使用 `*` 通配符,将名称、地址或主机名与该模式匹配的所有节点添加到子集中。 19 | - `master:true`,`data:true`,`ingest:true`,`voting_only:true`,`ml:true` 或 `coordinating_only:true`,分别将所有符合主节点资格的节点、所有数据节点、所有摄取节点、所有仅投票节点、所有机器学习节点和所有仅协调节点添加到子集中。 20 | - `master:false`,`data:false`,`ingest:false`,`voting_only:false`,`ml:false` 或 `coordinating_only:false`,分别从子集中移除所有符合主节点资格的节点、所有数据节点、所有摄取节点、所有仅投票节点、所有机器学习节点和所有仅协调节点。 21 | - 模式对,使用 `*` 通配符,其形式为 `attrname:attrvalue`,用于将名称和值符合相应模式的自定义节点属性添加到子集中。[自定义节点属性](/set_up_elasticsearch/configuring_elasticsearch/node_settings#自定义节点属性)是通过在配置文件中设置形式为 `node.attr.attrname:attrvalue` 的属性来配置的。 22 | 23 | :::note 提示 24 | 节点过滤器的运行顺序,这一点在使用从节点集中移除节点的过滤器时非常重要。例如,`_all,master:false` 表示除符合主节点条件的节点外的所有节点,但 `master:false,_all` 的意思与 `_all` 相同,因为 `_all` 过滤器在 `master:false` 过滤器之后运行。 25 | ::: 26 | 27 | :::note 提示 28 | 如果没有给出筛选条件,默认情况下会选择所有节点。但是,如果给定了任何筛选器,它们就会从一个空的所选子集开始运行。这意味着,`master:false` 等从所选子集中移除节点的筛选器只有在其他筛选器之后才有用。单独使用时,`master:false` 不会选择任何节点。 29 | ::: 30 | 31 | 下面是节点过滤器与节点信息 API 配合使用的一些示例。 32 | 33 | ```bash 34 | # If no filters are given, the default is to select all nodes 35 | GET /_nodes 36 | # Explicitly select all nodes 37 | GET /_nodes/_all 38 | # Select just the local node 39 | GET /_nodes/_local 40 | # Select the elected master node 41 | GET /_nodes/_master 42 | # Select nodes by name, which can include wildcards 43 | GET /_nodes/node_name_goes_here 44 | GET /_nodes/node_name_goes_* 45 | # Select nodes by address, which can include wildcards 46 | GET /_nodes/10.0.0.3,10.0.0.4 47 | GET /_nodes/10.0.0.* 48 | # Select nodes by role 49 | GET /_nodes/_all,master:false 50 | GET /_nodes/data:true,ingest:true 51 | GET /_nodes/coordinating_only:true 52 | GET /_nodes/master:true,voting_only:false 53 | # Select nodes by custom attribute (e.g. with something like `node.attr.rack: 2` in the configuration file) 54 | GET /_nodes/rack:2 55 | GET /_nodes/ra*:2 56 | GET /_nodes/ra*:2* 57 | ``` 58 | 59 | 60 | 61 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster.html) 62 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/create_data_stream.md: -------------------------------------------------------------------------------- 1 | # 创建数据流 2 | 3 | 创建一个新的[数据流](/data_streams)。 4 | 5 | ```bash 6 | PUT /_data_stream/my-data-stream 7 | ``` 8 | 9 | ## 请求 10 | 11 | `PUT /_data_stream/` 12 | 13 | ## 前置条件 14 | 15 | - 如果 Elasticsearch 安全特性启用,你必须有 `create_index` 或 `manage` 的[索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 16 | - 已启用数据流的匹配[索引模板](/index_templates)。参阅[设置数据流](/data_streams/set_up_a_data_stream)。 17 | 18 | ## 路径参数 19 | 20 | - `` 21 | 22 | (必须,字符串) 要创建的数据流的名称。数据流名称必须符合以下条件: 23 | 24 | - 只能是小写 25 | - 不能包含 `\`,`/`,`*`,`?`,`"`,`<`,`>`,`|`,`,`,`#`,`:` 或空格符 26 | - 不能以这些开头:`-`,`_`,`+`,或 `.ds-` 27 | - 长度不能超过 255 字节。多字节字符的计算速度更快。 28 | 29 | 30 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-data-stream.html) 31 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/data_stream_apis.md: -------------------------------------------------------------------------------- 1 | # 数据流 API 2 | 3 | 以下 API 可用于管理数据流: 4 | 5 | - [创建数据流](./create_data_stream) 6 | - [删除数据流](./delete_data_stream) 7 | - [获取数据流](./get_data_stream) 8 | - [迁移到数据流](./migrate_to_data_stream) 9 | - [数据流统计](./data_stream_stats) 10 | - [推广数据流](./promote_data_stream) 11 | - [修改数据流](./modify_data_stream) 12 | 13 | 以下 API 可用于管理数据流的内置生命周期: 14 | 15 | :::caution 警告 16 | 此功能为技术预览版,可能会在未来版本中更改或删除。Elastic 将努力修复任何问题,但技术预览版中的功能不受官方 GA 功能的支持服务级别协议约束。 17 | ::: 18 | 19 | - [更新数据流生命周期](./put_data_stream_lifecycle) [预览版] 20 | - [获取数据流生命周期](./get_data_stream_lifecycle) [预览版] 21 | - [删除数据流生命周期](./delete_data_stream_lifecycle) [预览版] 22 | - [解释数据流生命周期](./explain_data_stream_lifecycle) [预览版] 23 | - [获取数据流生命周期统计数据](./get_data_stream_lifecycle_state)[预览版] 24 | 25 | 以下 API 可用于[时序数据流](/data_streams/tsds): 26 | 27 | - [下采样](./downsample) 28 | 29 | 有关概念和教程,参阅[数据流](/data_streams)。 30 | 31 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-apis.html) 32 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/data_stream_stats.md: -------------------------------------------------------------------------------- 1 | # 数据流统计 API 2 | 3 | 检索一个或多个[数据流](/data_streams)的统计数据。 4 | 5 | ```bash 6 | GET /_data_stream/my-data-stream/_stats 7 | ``` 8 | 9 | ## 前置条件 10 | 11 | - 如果 Elasticsearch 安全特性启用,你必须有 `monitor` 或 `manage` 的[索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 12 | 13 | ## 请求 14 | 15 | `GET /_data_stream//_stats` 16 | 17 | ## 路径参数 18 | 19 | - `` 20 | 21 | (可选,字符串) 用于限制请求的数据流的逗号分隔列表。支持通配符表达式 (`*`)。 22 | 23 | 要以集群中的所有数据流为目标,请省略此参数或使用 `*`。 24 | 25 | ## 查询参数 26 | 27 | - `expand_wildcards` 28 | 29 | (可选,字符串)通配符模式可以匹配的数据流类型。支持逗号分隔值,例如 `open,hidden`。有效值为: 30 | 31 | - `all`,`hidden` 32 | 33 | 匹配任何数据流或索引,包括[隐藏的](/rest_apis/api_conventions/multi_target_syntax#隐藏数据流和索引)。 34 | 35 | - `open`,`closed` 36 | 37 | 匹配任何非隐藏的数据流。无法关闭 Data Streams。 38 | 39 | - `none` 40 | 41 | 不接受通配符模式。 42 | 43 | 默认为 `open`。 44 | 45 | - `human` 46 | 47 | (可选,布尔值) 如果为 `true`,则响应会包含以人类可读[字节值](/rest_apis/api_conventions#字节大小单位)表示的统计数据。默认为 `false`。 48 | 49 | ## 响应体 50 | 51 | - `_shards` 52 | 53 | (对象)包含试图执行请求的分片的信息。 54 | 55 | - `_shards` 属性 56 | 57 | - `total` 58 | 59 | (整数)尝试执行请求的分片总数。 60 | 61 | - `successful` 62 | 63 | (整数)成功执行请求的分片数。 64 | 65 | - `failed` 66 | 67 | (整数)未能执行请求的分片数量。 68 | 69 | - `data_stream_count` 70 | 71 | (整数)所选数据流的总数。 72 | 73 | - `backing_indices` 74 | 75 | (整数)所选数据流的备份索引总数。 76 | 77 | - `total_store_size` 78 | 79 | ([字节值](/rest_apis/api_conventions#字节大小单位))所选数据流的所有分块的总大小。只有当 `human` 查询参数为 `true` 时,才会包含此属性。 80 | 81 | - `total_store_size_bytes` 82 | 83 | (整数)所选数据流所有分块的总大小(字节)。 84 | 85 | - `data_streams` 86 | 87 | (对象数组) 包含所选数据流的统计数据。 88 | 89 | - `data_streams` 对象属性 90 | 91 | - `data_stream` 92 | 93 | (字符串) 数据流的名称。 94 | 95 | - `backing_indices` 96 | 97 | (整数)数据流的当前后备索引数。 98 | 99 | - `store_size` 100 | 101 | ([字节值](/rest_apis/api_conventions#字节大小单位))数据流后备索引所有分片的总大小。只有当 `human` 查询参数为 `true` 时,才会返回该参数。 102 | 103 | - `store_size_bytes` 104 | 105 | (整数)数据流后备索引所有分片的总大小(以字节为单位)。 106 | 107 | - `maximum_timestamp` 108 | 109 | (整数) 数据流的最高 `@timestamp` 值,转换为 [Unix epoch](https://en.wikipedia.org/wiki/Unix_time)以来的毫秒数。 110 | 111 | :::note 提示 112 | 如果满足以下一个或多个条件,数据流中的 `@timestamp` 值可能高于此值: 113 | - 数据流包含已关闭的后备索引。 114 | - 生成时间较短的备份索引包含较高的 `@timestamp` 值。 115 | ::: 116 | 117 | ## 示例 118 | 119 | ```bash 120 | GET /_data_stream/my-data-stream*/_stats?human=true 121 | ``` 122 | 123 | API 返回以下响应。 124 | 125 | ```json 126 | { 127 | "_shards": { 128 | "total": 10, 129 | "successful": 5, 130 | "failed": 0 131 | }, 132 | "data_stream_count": 2, 133 | "backing_indices": 5, 134 | "total_store_size": "7kb", 135 | "total_store_size_bytes": 7268, 136 | "data_streams": [ 137 | { 138 | "data_stream": "my-data-stream", 139 | "backing_indices": 3, 140 | "store_size": "3.7kb", 141 | "store_size_bytes": 3772, 142 | "maximum_timestamp": 1607512028000 143 | }, 144 | { 145 | "data_stream": "my-data-stream-two", 146 | "backing_indices": 2, 147 | "store_size": "3.4kb", 148 | "store_size_bytes": 3496, 149 | "maximum_timestamp": 1607425567000 150 | } 151 | ] 152 | } 153 | ``` 154 | 155 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-stats-api.html) 156 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/delete_data_stream.md: -------------------------------------------------------------------------------- 1 | # 删除数据流 API 2 | 3 | 删除一个或多个[数据流](/data_streams)及其支持索引。参阅[删除数据流](/data_streams/set_up_a_data_stream#删除数据流)。 4 | 5 | ```bash 6 | DELETE /_data_stream/my-data-stream 7 | ``` 8 | 9 | ## 请求 10 | 11 | `DELETE /_data_stream/` 12 | 13 | ## 前置条件 14 | 15 | - 如果 Elasticsearch 安全特性启用,你必须有 `delete_index` 或 `manage` 的[索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 16 | 17 | ## 路径参数 18 | 19 | - `` 20 | 21 | (必需,字符串)要删除的数据流的逗号分隔列表。支持通配符 (`*`) 表达式。 22 | 23 | ## 查询参数 24 | 25 | - `expand_wildcards` 26 | 27 | (可选,字符串)通配符模式可以匹配的数据流类型。支持逗号分隔值,例如 `open,hidden`。有效值为: 28 | 29 | - `all`,`hidden` 30 | 31 | 匹配任何数据流或索引,包括[隐藏的](/rest_apis/api_conventions/multi_target_syntax#隐藏数据流和索引)。 32 | 33 | - `open`,`closed` 34 | 35 | 匹配任何非隐藏的数据流。无法关闭 Data Streams。 36 | 37 | - `none` 38 | 39 | 不接受通配符模式。 40 | 41 | 默认为 `open`。 42 | 43 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-data-stream.html#delete-data-stream-api-prereqs) 44 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/delete_data_stream_lifecycle.md: -------------------------------------------------------------------------------- 1 | # 删除数据流生命周期 2 | 3 | :::info 新 API 参考 4 | 有关最新 API 的详细信息,参阅[数据流 API](https://www.elastic.co/docs/api/doc/elasticsearch/v8/group/endpoint-data-stream)。 5 | ::: 6 | 7 | 从一组数据流中删除[生命周期](/data_streams/data_stream_lifecycle)。 8 | 9 | ## 前置条件 10 | 11 | - 如果 Elasticsearch 安全特性启用,你必须有 `manage_data_stream_lifecycle` 的索引权限。更多信息,参阅[安全权限](/secure_the_elastic_statck/user_authorization/security_privileges)。 12 | 13 | ## 请求 14 | 15 | `DELETE _data_stream//_lifecycle` 16 | 17 | ## 描述 18 | 19 | 从指定的数据流中删除生命周期。如果提供了多个数据流,但其中只要有一个不存在,那么删除所有数据流中的生命周期都将失败,API 将以 `404` 响应。 20 | 21 | ## 路径参数 22 | 23 | - `` 24 | 25 | (必需,字符串)要删除的数据流的逗号分隔列表。支持通配符 (`*`) 表达式。要针对所有数据流,请使用 `*` 或 `_all`。 26 | 27 | ## 查询参数 28 | 29 | - `expand_wildcards` 30 | 31 | (可选,字符串)通配符模式可以匹配的数据流类型。支持逗号分隔值,例如 `open,hidden`。有效值为: 32 | 33 | - `all`,`hidden` 34 | 35 | 匹配任何数据流或索引,包括[隐藏的](/rest_apis/api_conventions/multi_target_syntax#隐藏数据流和索引)。 36 | 37 | - `open`,`closed` 38 | 39 | 匹配任何非隐藏的数据流。无法关闭 Data Streams。 40 | 41 | - `none` 42 | 43 | 不接受通配符模式。 44 | 45 | 默认为 `open`。 46 | 47 | ## 示例 48 | 49 | 下面的示例删除了 `my-data-stream` 的生命周期: 50 | 51 | ```bash 52 | DELETE _data_stream/my-data-stream/_lifecycle 53 | ``` 54 | 55 | 从所有选定数据流中成功删除策略后,会收到以下结果: 56 | 57 | ```json 58 | { 59 | "acknowledged": true 60 | } 61 | ``` 62 | 63 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams-delete-lifecycle.html) 64 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/downsample.md: -------------------------------------------------------------------------------- 1 | # 下采样索引 API 2 | 3 | :::info 新 API 参考 4 | 有关最新 API 的详细信息,参阅[数据流 API](https://www.elastic.co/docs/api/doc/elasticsearch/v8/group/endpoint-data-stream)。 5 | ::: 6 | 7 | 聚合时间序列 (TSDS) 索引,并存储按配置时间间隔分组的每个指标字段的预计算统计摘要(`min`、`max`、`sum`、`value_count` 和 `avg`)。例如,包含每 10 秒采样一次的指标的 TSDS 索引可以缩减采样为每小时索引。一小时间隔内的所有文档都会汇总并作为单个文档存储在下采样索引中。 8 | 9 | ```bash 10 | POST /my-time-series-index/_downsample/my-downsampled-time-series-index 11 | { 12 | "fixed_interval": "1d" 13 | } 14 | ``` 15 | 16 | 请查阅[下采样](/data_streams/tsds/downsamping_a_time_series_data_stream)文档,了解概述、向下采样过程的详情以及手动运行向下采样和作为 ILM 策略的一部分运行向下采样的示例。 17 | 18 | ## 请求 19 | 20 | `POST //_downsample/` 21 | 22 | ## 前置条件 23 | 24 | - 仅支持[时序数据流](/data_streams/tsds)中的索引。 25 | - 如果启用了 Elasticsearch 安全功能,则必须拥有数据流的 `all` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 26 | - 源索引上不能[定义字段或文档级安全性](/secure_the_elastic_statck/user_authorization/setting_up_field_and_document_level_security)。 27 | - 源索引必须是只读的(`index.blocks.write: true`)。 28 | 29 | ## 路径参数 30 | 31 | - `` 32 | 33 | (可选,字符串)要进行下采样的时间序列索引名称。 34 | 35 | - `` 36 | 37 | (必须,字符串) 要创建的索引的名称。 38 | 39 | - 只能是小写字符 40 | - 不能包含字符:`\`、`/`、`*`、`?`、`"`、`<`、`>`、`|`、` `(空格)、`,`、`#` 41 | - 7.0 之前索引可以包含冒号(:),但在 7.0 之后不推荐。 42 | - 不能以 `-`、`_`、`+` 开头 43 | - 不能是 `.` 或 `..` 44 | - 长度不能超过 255 字节(注意是字节,所以多字节字符会更快达到 255 的限制) 45 | - 名字以 `.` 开头不推荐,除非由插件管理的[隐藏索引](/index_modules)和内部索引 46 | 47 | ## 查询参数 48 | 49 | - `fixed_interval` 50 | 51 | (必填,[时间单位](/rest_apis/api_convention/common_options#时间单位))汇总原始时间序列索引的时间间隔。例如,60m 为每个 60 分钟(每小时)间隔生成一个文档。这遵循 Elasticsearch 中其他地方使用的标准时间格式语法。 52 | 53 | :::note 提示 54 | 更小、更细的区间所占空间也更大。 55 | ::: 56 | 57 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-downsample-data-stream.html) 58 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/explain_data_stream_lifecycle.md: -------------------------------------------------------------------------------- 1 | # 解释数据流生命周期 2 | 3 | :::info 新 API 参考 4 | 有关最新 API 的详细信息,参阅[数据流 API](https://www.elastic.co/docs/api/doc/elasticsearch/v8/group/endpoint-data-stream)。 5 | ::: 6 | 7 | 读取一个或多个数据流后备索引的当前[数据流生命周期](/data_streams/data_stream_lifecycle)状态。 8 | 9 | ## 前置条件 10 | 11 | - 如果 Elasticsearch 安全特性启用,你必须有 `manage_data_stream_lifecycle` 的索引权限或 `view_index_metadata` 索引权限来使用此 API。更多信息,参阅[安全权限](/secure_the_elastic_statck/user_authorization/security_privileges)。 12 | 13 | ## 请求 14 | 15 | `GET /_lifecycle/explain` 16 | 17 | ## 描述 18 | 19 | 读取有关索引或数据流当前数据流生命周期状态的信息,如创建索引以来的时间、翻转以来的时间、管理索引的生命周期配置,或 Elasticsearch 在生命周期执行期间可能遇到的任何错误。 20 | 21 | ## 路径参数 22 | 23 | - `` 24 | 25 | (必需,字符串) 用逗号分隔的索引或数据流列表。 26 | 27 | ## 查询参数 28 | 29 | - `include_defaults` 30 | 31 | (可选,布尔值)包含与目标生命周期相关的默认配置。默认为 `false`。 32 | 33 | - `master_timeout` 34 | 35 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待主节点的时间。如果在超时前主节点不可用,则请求失败并返回错误。默认为 `30s`。也可以设置为 `-1`,表示请求永不超时。 36 | 37 | ## 示例 38 | 39 | 如果要检索数据流中所有后备索引的生命周期状态,可以使用数据流名称。为简单起见,以下示例检索了一个后备索引 `.ds-metrics-2023.03.22-000001` 的生命周期状态: 40 | 41 | ```bash 42 | GET .ds-metrics-2023.03.22-000001/_lifecycle/explain 43 | ``` 44 | 45 | 如果该索引由数据流生命周期管理,则解释将显示 `managed_by_lifecycle` 字段设置为 `true`,响应的其余部分将包含有关该索引生命周期执行状态的信息: 46 | 47 | ```json 48 | { 49 | "indices": { 50 | ".ds-metrics-2023.03.22-000001": { 51 | "index" : ".ds-metrics-2023.03.22-000001", 52 | "managed_by_lifecycle" : true, 53 | "index_creation_date_millis" : 1679475563571, 54 | "time_since_index_creation" : "843ms", 55 | "rollover_date_millis" : 1679475564293, 56 | "time_since_rollover" : "121ms", 57 | "lifecycle" : { }, 58 | "generation_time" : "121ms" 59 | } 60 | } 61 | ``` 62 | 1. `"managed_by_lifecycle" : true`:显示索引是否由数据流生命周期管理。如果索引不是由数据流生命周期管理,则不会显示其他字段 63 | 2. `"index_creation_date_millis" : 1679475563571`:创建索引的时间,该时间戳用于确定何时翻转 64 | 3. `"time_since_index_creation" : "843ms"`:索引创建后的时间(用于通过 `max_age` 计算何时翻转索引) 65 | 4. `"rollover_date_millis" : 1679475564293`:索引翻转的时间。如果索引没有滚动,则不会显示。 66 | 5. `"time_since_rollover" : "121ms"`:翻转后的时间。如果索引没有滚动,则不会显示。 67 | 6. `"lifecycle" : { }`:适用于该索引的生命周期配置(在父数据流中进行了配置) 68 | 7. `"generation_time" : "121ms"`:索引的生成时间表示索引开始进入生命周期中用户可配置/业务特定部分(如保留)的时间。如果存在 `generation_time`,则从该日期开始计算生成时间;如果存在翻转日期,则从该日期开始计算生成时间;如果其他两个日期都不存在,则从创建日期开始计算生成时间。如果该索引是写入索引,则不会报告 `generation_time`,因为它不符合保留或生命周期其他部分的条件。 69 | 70 | `explain` 还会报告与目标索引生命周期执行相关的任何错误: 71 | 72 | ```json 73 | { 74 | "indices": { 75 | ".ds-metrics-2023.03.22-000001": { 76 | "index" : ".ds-metrics-2023.03.22-000001", 77 | "managed_by_lifecycle" : true, 78 | "index_creation_date_millis" : 1679475563571, 79 | "time_since_index_creation" : "843ms", 80 | "lifecycle" : { 81 | "enabled": true 82 | }, 83 | "error": "{\"type\":\"validation_exception\",\"reason\":\"Validation Failed: 1: this action would add [2] shards, but this cluster 84 | currently has [4]/[3] maximum normal shards open;\"}" 85 | } 86 | } 87 | ``` 88 | 89 | 1. `"error":`:由于集群中允许的分片数量限制,无法翻转目标索引。 90 | 91 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams-explain-lifecycle.html) 92 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/get_data_stream_lifecycle.md: -------------------------------------------------------------------------------- 1 | # 获取数据流的生命周期 2 | 3 | 获取一组[数据流](/data-streams)的[生命周期](/data-streams/data-stream-lifecycle)。 4 | 5 | ## 前置条件 6 | 7 | - 如果 Elasticsearch 安全特性启用,你使用此 API 必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限) 或 `manage_data_stream_lifecycle` 索引权限或 `view_index_metadata` 索引权限。更多信息,参阅[安全权限](/secure_the_elastic_statck/user_authorization/security_privileges)。 8 | 9 | ## 请求 10 | 11 | `GET _data_stream//_lifecycle` 12 | 13 | ## 描述 14 | 15 | 获取指定数据流的生命周期。如果请求多个数据流,但其中至少有一个不存在,那么 API 将以 404 响应,因为至少有一个请求的资源无法检索。如果请求的数据流没有配置生命周期,它们仍将包含在 API 响应中,但 `lifecycle` 关键字将丢失。 16 | 17 | ## 路径参数 18 | 19 | - `` 20 | 21 | (必需,字符串) 用于限制请求的数据流的逗号分隔列表。支持通配符 (`*`)。要针对所有数据流,请使用 `*` 或 `_all`。 22 | 23 | ## 查询参数 24 | 25 | - `expand_wildcards` 26 | 27 | (可选,字符串)通配符模式可以匹配的数据流类型。支持逗号分隔值,例如 `open,hidden`。有效值为: 28 | 29 | - `all`,`hidden` 30 | 31 | 匹配任何数据流或索引,包括[隐藏的](/rest_apis/api_conventions/multi_target_syntax#隐藏数据流和索引)。 32 | 33 | - `open`,`closed` 34 | 35 | 匹配任何非隐藏的数据流。无法关闭 Data Streams。 36 | 37 | - `none` 38 | 39 | 不接受通配符模式。 40 | 41 | 默认为 `open`。 42 | 43 | - `include_defaults` 44 | 45 | (可选,布尔值) 如果为 `true`,则在响应中返回所有默认设置。默认为 `false`。 46 | 47 | ## 响应体 48 | 49 | - `data_streams` 50 | 51 | (对象数组)包含有关检索到的数据流生命周期的信息。 52 | 53 | - `data_streams` 对象属性 54 | 55 | - `name` 56 | 57 | (字符串) 数据流的名称。 58 | 59 | - `lifecycle` 60 | 61 | (可选,对象) 62 | 63 | `lifecycle` 属性 64 | 65 | - `data_retention` 66 | 67 | (可选,字符串) 如果已定义,则表示数据流所有者为该数据流要求的保留时间。 68 | 69 | - `effective_retention` 70 | 71 | (可选,字符串)如果定义,则添加到此数据流中的每个文档都将至少在此时间段内保存。在此期限之后的任何时间,文档都可能被删除。如果为空,该数据流中的每份文档都将无限期存储。为空时,该数据流中的每份文档都将无限期保存。有效保留时间的计算方法如[教程](/data_streams/data_stream_lifecycle/tutorial_data_stream_retention#如何计算有效保留时间?)所述。 72 | 73 | - `retention_determined_by` 74 | 75 | (可选,字符串) 保留的来源,可以是三种值之一:`data_stream_configuration`、`default_retention` 或 `max_retention`。 76 | 77 | - `rollover` 78 | 79 | (可选,对象)由集群设置 `cluster.lifecycle.default.rollover` 配置的触发后备索引翻转的条件。该属性是一个实现细节,只有当查询参数 `include_defaults` 设置为 `true` 时才能检索到。此字段的内容可能会更改。 80 | 81 | - `global_retention` 82 | 83 | (对象)包含全局最大保留和默认保留。如果未配置全局保留,则该对象为空。 84 | 85 | - `global_retention` 属性 86 | 87 | - `max_retention` 88 | 89 | (可选,字符串) 数据流生命周期管理的数据流的有效保留时间不能超过此值。 90 | 91 | - `default_retention` 92 | 93 | (可选,字符串) 这将是数据流生命周期管理的、未指定 `data_retention` 的数据流的有效保留时间。 94 | 95 | ## 示例 96 | 97 | 让我们检索生命周期: 98 | 99 | ```bash 100 | GET _data_stream/my-data-stream*/_lifecycle 101 | ``` 102 | 103 | 响应如下: 104 | 105 | ```json 106 | { 107 | "data_streams": [ 108 | { 109 | "name": "my-data-stream-1", 110 | "lifecycle": { 111 | "enabled": true, 112 | "data_retention": "7d", 113 | "effective_retention": "7d", 114 | "retention_determined_by": "data_stream_configuration" 115 | } 116 | }, 117 | { 118 | "name": "my-data-stream-2", 119 | "lifecycle": { 120 | "enabled": true, 121 | "data_retention": "7d", 122 | "effective_retention": "7d", 123 | "retention_determined_by": "data_stream_configuration" 124 | } 125 | } 126 | ], 127 | "global_retention": {} 128 | } 129 | ``` 130 | 131 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams-get-lifecycle.html) 132 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/get_data_stream_lifecycle_state.md: -------------------------------------------------------------------------------- 1 | # 获取数据流生命周期统计信息 2 | 3 | :::info 新 API 参考 4 | 有关最新 API 的详细信息,参阅[数据流 API](https://www.elastic.co/docs/api/doc/elasticsearch/v8/group/endpoint-data-stream)。 5 | ::: 6 | 7 | 获取有关[数据流生命周期](/data_streams/data_stream_lifecycle)执行情况的统计信息。 8 | 9 | ## 前置条件 10 | 11 | - 如果 Elasticsearch 安全特性启用,你必须有 `monitor` 或 `manage` [集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)来使用此 API。 12 | 13 | ## 请求 14 | 15 | `GET _lifecycle/stats` 16 | 17 | ## 描述 18 | 19 | 获取有关数据流生命周期执行情况的统计信息。数据流级别的统计信息只包括数据流生命周期管理的数据流的统计信息。 20 | 21 | ## 响应体 22 | 23 | - `last_run_duration_in_millis` 24 | 25 | (可选,长整数)最后一次执行数据流生命周期的持续时间。 26 | 27 | - `time_between_starts_in_millis` 28 | 29 | (可选,长整数)最后两次数据流生命周期执行开始之间的时间间隔。该值应近似于 [`data_streams.lifecycle.poll_interval`](/set_up_elasticsearch/configuring_elasticsearch/data_stream_lifecycle_settings)。 30 | 31 | - `data_stream_count` 32 | 33 | (整数) 当前由数据流生命周期管理的数据流的计数。 34 | 35 | - `data_streams` 36 | 37 | (对象数组)包含检索到的数据流生命周期的相关信息。 38 | 39 | - `data_streams` 中的对象属性 40 | 41 | - `name` 42 | 43 | (字符串) 数据流的名称。 44 | 45 | - `backing_indices_in_total` 46 | 47 | (整数)由数据流生命周期管理的该数据流后备索引的计数。 48 | 49 | - `backing_indices_in_error` 50 | 51 | (整数)由数据流生命周期管理并已遇到错误的数据流后备索引的计数。 52 | 53 | ## 示例 54 | 55 | 让我们检索已执行过一次以上生命周期的群集的数据流生命周期统计信息: 56 | 57 | ```bash 58 | GET _lifecycle/stats?human&pretty 59 | ``` 60 | 61 | 回复内容如下 62 | 63 | ```json 64 | { 65 | "last_run_duration_in_millis": 2, 66 | "last_run_duration": "2ms", 67 | "time_between_starts_in_millis": 9998, 68 | "time_between_starts": "9.99s", 69 | "data_streams_count": 2, 70 | "data_streams": [ 71 | { 72 | "name": "my-data-stream", 73 | "backing_indices_in_total": 2, 74 | "backing_indices_in_error": 0 75 | }, 76 | { 77 | "name": "my-other-stream", 78 | "backing_indices_in_total": 2, 79 | "backing_indices_in_error": 1 80 | } 81 | ] 82 | } 83 | ``` 84 | 85 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams-get-lifecycle-stats.html) 86 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/migrate_to_data_stream.md: -------------------------------------------------------------------------------- 1 | # 迁移数据流 API 2 | 3 | 将[索引别名](/aliases)转换为[数据流](/data_streams)。 4 | 5 | ```bash 6 | POST /_data_stream/_migrate/my-logs 7 | ``` 8 | 9 | ## 请求 10 | 11 | `POST /_data_stream/_migrate/` 12 | 13 | ## 前置条件 14 | 15 | - 如果 Elasticsearch 安全特性启用,你必须有 `manage` 的[索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 16 | - 已启用数据流的匹配[索引模板](/index_templates)。参阅[设置数据流](/data_streams/set_up_a_data_stream)。 17 | 18 | ## 路径参数 19 | 20 | - `` 21 | 22 | (必需,字符串)要转换为数据流的索引别名的名称。别名必须符合以下条件: 23 | 24 | - 别名必须有一个[写索引](/aliases#写索引)。 25 | - 别名的所有索引都有一个 `date` 或 `date_nanos` 字段类型的 `@timestamp` 字段映射。 26 | - 别名必须没有任何[过滤器](/aliases#过滤别名)。 27 | - 别名不得使用[自定义路由](/aliases#路由)。 28 | 29 | 如果请求成功,则会删除别名并创建同名数据流。别名的索引将成为数据流的隐藏备份索引。别名的写索引将成为数据流的写索引。 30 | 31 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-migrate-to-data-stream.html) 32 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/modify_data_stream.md: -------------------------------------------------------------------------------- 1 | # 修改数据流 API 2 | 3 | 在单个原子操作中执行一个或多个[数据流](/data_streams)修改操作。 4 | 5 | ```bash 6 | POST _data_stream/_modify 7 | { 8 | "actions": [ 9 | { 10 | "remove_backing_index": { 11 | "data_stream": "my-logs", 12 | "index": ".ds-my-logs-2099.01.01-000001" 13 | } 14 | }, 15 | { 16 | "add_backing_index": { 17 | "data_stream": "my-logs", 18 | "index": "index-to-add" 19 | } 20 | } 21 | ] 22 | } 23 | ``` 24 | 25 | ## 请求 26 | 27 | `POST /_data_stream/_modify` 28 | 29 | ## 请求体 30 | 31 | - `actions` 32 | 33 | (必填,对象数组)要执行的操作。 34 | 35 | - `actions` 对象属性 36 | 37 | - `` 38 | 39 | (必填,对象)键是操作类型。至少需要一个操作。 40 | 41 | - 有效的 `` 键 42 | 43 | - `add_backing_index` 44 | 45 | 添加现有索引作为数据流的后备索引。作为该操作的一部分,索引将被隐藏。 46 | 47 | :::warning 警告 48 | 使用 add_backing_index 操作添加索引可能会导致不当的数据流行为。这应该被视为专家级 API。 49 | ::: 50 | 51 | 52 | - `remove_backing_index` 53 | 54 | 从数据流中删除一个后备索引。作为该操作的一部分,索引将被取消隐藏。不能删除数据流的写索引。 55 | 56 | - `` 属性(对象主体包含的操作选项) 57 | 58 | - `data_stream` 59 | 60 | (必需*,字符串) 操作所针对的数据流。 61 | 62 | - `index` 63 | 64 | (必需*,字符串)操作索引。 65 | 66 | 67 | 68 | 69 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/modify-data-streams-api.html) 70 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/promote_data_stream.md: -------------------------------------------------------------------------------- 1 | # 推广数据流 API 2 | 3 | 推广[数据流](/data_streams) API 的目的是将 CCR 复制的数据流转化为常规数据流。 4 | 5 | 通过 CCR 自动跟踪,远程群集的数据流可复制到本地群集。这些数据流无法在本地群集中滚动。只有当上游数据流滚动时,这些复制的数据流才会滚动。如果远程群集不再可用,本地群集中的数据流可升级为常规数据流,从而允许这些数据流在本地群集中滚动。 6 | 7 | ```bash 8 | POST /_data_stream/_promote/my-data-stream 9 | ``` 10 | 11 | ## 请求 12 | 13 | `POST /_data_stream/_promote/` 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你必须有 `manage_follow_index` 的[集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)。 18 | 19 | ## 路径参数 20 | 21 | - `` 22 | 23 | (必填,字符串) 要推广的数据流名称。 24 | 25 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/promote-data-stream-api.html) 26 | -------------------------------------------------------------------------------- /docs/rest_apis/data_stream_apis/put_data_stream_lifecycle.md: -------------------------------------------------------------------------------- 1 | # 设置数据流生命周期 2 | 3 | 为目标[数据流](/data-streams)配置数据流[生命周期](/data-streams/data-stream-lifecycle)。 4 | 5 | ## 前置条件 6 | 7 | - 如果 Elasticsearch 安全特性启用,你使用此 API 必须有 `manage_data_stream_lifecycle` 或更高的[索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。更多信息,参阅[安全权限](/secure_the_elastic_statck/user_authorization/security_privileges)。 8 | 9 | ## 请求 10 | 11 | `PUT _data_stream//_lifecycle` 12 | 13 | ## 描述 14 | 15 | 为目标数据流配置数据流生命周期。如果提供了多个数据流,但其中有一个以上不存在,那么生命周期的更新将对所有数据流都失败,API 将响应 `404`。 16 | 17 | ## 路径参数 18 | 19 | - `` 20 | 21 | (必需,字符串) 用于限制请求的数据流的逗号分隔列表。支持通配符 (`*`)。要针对所有数据流,请使用 `*` 或 `_all`。 22 | 23 | ## 查询参数 24 | 25 | - `expand_wildcards` 26 | 27 | (可选,字符串)通配符模式可以匹配的数据流类型。支持逗号分隔值,例如 `open,hidden`。有效值为: 28 | 29 | - `all`,`hidden` 30 | 31 | 匹配任何数据流或索引,包括[隐藏的](/rest_apis/api_conventions/multi_target_syntax#隐藏数据流和索引)。 32 | 33 | - `open`,`closed` 34 | 35 | 匹配任何非隐藏的数据流。无法关闭 Data Streams。 36 | 37 | - `none` 38 | 39 | 不接受通配符模式。 40 | 41 | 默认为 `open`。 42 | 43 | ## 请求体 44 | 45 | - `lifecycle` 46 | 47 | (必需,对象) 48 | 49 | - `lifecycle` 的属性 50 | 51 | - `data_retention` 52 | 53 | (可选,字符串)如果定义,则添加到此数据流中的每个文档都将至少在此时间段内保存。在此期限之后的任何时间,文档都可能被删除。如果为空,则该数据流中的每份文档都将无限期存储。 54 | 55 | - `enabled` 56 | 57 | (可选,布尔值)如果定义,则打开/关闭(`true`/`false`)该数据流的数据流生命周期。禁用(`enabled: false`)的数据流生命周期对数据流没有任何影响。默认为 `true`。 58 | 59 | - `downsampling` 60 | 61 | (可选,数组)一个可选的下采样配置对象数组,每个对象都定义了一个后间隔(`after`)和一个固定间隔(`fixed_interval`),后间隔代表何时要对后备索引进行下采样(时间范围从索引滚动开始计算,即生成时间),`fixed_interval` 代表下采样间隔(`fixed_interval` 最小值为 `5m`)。最多可配置 10 轮向下采样。参阅下面的[配置](#示例)示例。 62 | 63 | ## 示例 64 | 65 | 下面的示例设置了 `my-data-stream` 的生命周期: 66 | 67 | ```bash 68 | PUT _data_stream/my-data-stream/_lifecycle 69 | { 70 | "data_retention": "7d" 71 | } 72 | ``` 73 | 74 | 当生命周期在所有数据流中更新成功后,你会收到以下结果: 75 | 76 | ```json 77 | { 78 | "acknowledged": true 79 | } 80 | ``` 81 | 82 | 下面的示例配置了两轮下采样,第一轮在后备索引滚动一天后开始(或更晚,如果索引仍在其写入接受时间范围内),间隔为 `10m`,第二轮在滚动 7 天后开始,间隔为 `1d`: 83 | 84 | ```bash 85 | PUT _data_stream/my-weather-sensor-data-stream/_lifecycle 86 | { 87 | "downsampling": [ 88 | { 89 | "after": "1d", 90 | "fixed_interval": "10m" 91 | }, 92 | { 93 | "after": "7d", 94 | "fixed_interval": "1d" 95 | } 96 | ] 97 | } 98 | ``` 99 | 100 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/data-streams-put-lifecycle.html) 101 | -------------------------------------------------------------------------------- /docs/rest_apis/document_apis/delete.md: -------------------------------------------------------------------------------- 1 | # 删除 API 2 | 3 | 从指定索引中删除 JSON 文档。 4 | 5 | ## 请求 6 | 7 | `DELETE //_doc/<_id>` 8 | 9 | ## 前置条件 10 | 11 | - 如果启用了 Elasticsearch 安全功能,则必须拥有目标索引或索引别名的 `delete` 或 `write` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 12 | 13 | ## 说明 14 | 15 | 你可以用 `DELETE` 从索引中删除文档。您必须指定索引名称和文档 ID。 16 | 17 | :::tip 注意 18 | 不能直接向数据流发送删除请求。要删除数据流中的文档,必须以包含该文档的备用索引为目标。参阅[更新或删除备用索引中的文档](/data_streams/use_a_data_stream#更新或删除备份索引中的文档)。 19 | ::: 20 | 21 | ### 乐观并发控制 22 | 23 | 删除操作可以是有条件的,只有在文档的最后一次修改被分配给 `if_seq_no` 和 `if_primary_term` 参数指定的序列号和主要术语时才会执行。如果检测到不匹配,操作将导致 `VersionConflictException` 和状态代码 `409`。有关详细信息,参阅[乐观并发控制](/rest_apis/document_apis/docs_index#乐观并发控制)。 24 | 25 | ### 版本控制 26 | 27 | 索引中的每个文档都有版本。删除文档时,可以指定版本,以确保我们要删除的相关文档确实正在被删除,而且在此期间没有发生变化。对文档执行的每次写操作(包括删除)都会导致其版本递增。删除文档后,其版本号会在短时间内保持可用,以便对并发操作进行控制。已删除文档的版本保持可用的时间长度由 `index.gc_deletes` 索引设置决定,默认为 60 秒。 28 | 29 | ### 路由 30 | 31 | 如果在编制索引时使用了路由,那么删除文档时也需要指定路由值。 32 | 33 | 如果 `_routing` 映射设置为 `required` 且未指定路由值,删除 API 将抛出 `RoutingMissingException` 并拒绝请求。 34 | 35 | 示例: 36 | 37 | ```bash 38 | DELETE /my-index-000001/_doc/1?routing=shard-1 39 | ``` 40 | 41 | 该请求会删除 id 为 `1` 的文档,但会根据用户进行路由。如果未指定正确的路由,则不会删除文档。 42 | 43 | ### 自动创建索引 44 | 45 | 如果使用了[外部版本控制变量](/rest_apis/document_apis/docs_index),删除操作会自动创建指定的索引(如果该索引不存在)。有关手动创建索引的信息,参阅[创建索引 API](/rest_apis/index_apis/create_index)。 46 | 47 | ### 分布式 48 | 49 | 删除操作会被散列到一个特定的分片 id 中。然后,它会被重定向到该 id 组中的主分区,并复制(如需要)到该 id 组中的分区副本。 50 | 51 | ### 等待活动分片 52 | 53 | 在提出删除请求时,可以设置 `wait_for_active_shards` 参数,要求在开始处理删除请求之前,至少有多少分片副本处于活动状态。详情和使用示例参阅[此处](/rest_apis/document_apis/docs_index#活动分片)。 54 | 55 | ### 刷新 56 | 57 | 控制搜索何时可以看到该请求所做的更改。参阅[刷新](/rest_apis/document_apis/refresh)。 58 | 59 | ### 超时 60 | 61 | 当执行删除操作时,指定执行删除操作的主分区可能不可用。造成这种情况的原因可能是主分区目前正在从存储中恢复或正在进行搬迁。默认情况下,删除操作最多会等待主分区可用 1 分钟,然后才会失败并响应错误。`timeout` 参数可用于明确指定等待时间。下面是一个将其设置为 5 分钟的示例: 62 | 63 | ```bash 64 | DELETE /my-index-000001/_doc/1?timeout=5m 65 | ``` 66 | 67 | ## 路径参数 68 | 69 | - `` 70 | (必需,字符串)目标索引的名称。 71 | - `<_id>` 72 | (必需,字符串)文档的唯一标识符。 73 | 74 | ## 查询参数 75 | 76 | - `if_seq_no` 77 | (可选,整数) 只有当文档具有此序列号时才执行操作。参阅[乐观并发控制](/rest_apis/document_apis/docs_index#乐观并发控制)。 78 | - `if_primary_term` 79 | (可选,整数) 只有当文档具有此序列号时才执行操作。参阅[乐观并发控制](/rest_apis/document_apis/docs_index#乐观并发控制)。 80 | - `refresh` 81 | (可选,枚举)如果为 `true`,Elasticsearch 会刷新受影响的分片,使该操作在搜索中可见;如果为 `wait_for`,则等待刷新,使该操作在搜索中可见;如果为 `false`,则不刷新。有效值:`true`、`false`、`wait_for`。默认值:`false`。 82 | - `routing` 83 | (可选,字符串) 用于将操作路由到特定分区的自定义值。 84 | - `timeout` 85 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))[等待活动分片](/rest_apis/document_apis/docs_index#活动分片)的时间。默认为 `1m`(一分钟)。 86 | - `version` 87 | (可选,整数)用于并发控制的明确版本号。指定的版本必须与文档的当前版本一致,请求才能成功。 88 | - `version_type` 89 | (可选,枚举) 特定版本类型:`external`、`external_gte`。 90 | - `wait_for_active_shards` 91 | (可选,字符串) 进行操作前必须激活的分片副本数量。设置为全部或任何正整数,最多不超过索引中的分片总数(`number_of_replicas+1`)。默认值:`1`,主分区。 92 | 93 | 参阅[活动分片](/rest_apis/document_apis/docs_index#活动分片) 94 | 95 | ## 示例 96 | 97 | 从 `my-index-000001` 索引中删除 JSON 文档 `1`: 98 | 99 | ```bash 100 | DELETE /my-index-000001/_doc/1 101 | ``` 102 | 103 | API 返回以下结果: 104 | 105 | ```json 106 | { 107 | "_shards": { 108 | "total": 2, 109 | "failed": 0, 110 | "successful": 2 111 | }, 112 | "_index": "my-index-000001", 113 | "_id": "1", 114 | "_version": 2, 115 | "_primary_term": 1, 116 | "_seq_no": 5, 117 | "result": "deleted" 118 | } 119 | ``` 120 | 121 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html) 122 | -------------------------------------------------------------------------------- /docs/rest_apis/document_apis/document_apis.md: -------------------------------------------------------------------------------- 1 | # 文档 API 2 | 3 | 本章首先简要介绍 Elasticsearch 的数据复制模型,然后详细描述以下 CRUD API: 4 | 5 | ## 单文档 API 6 | 7 | - [索引](/rest_apis/document_apis/docs_index) 8 | - [获取](/rest_apis/document_apis/get) 9 | - [删除](/rest_apis/document_apis/delete) 10 | - [更新](/rest_apis/document_apis/update) 11 | 12 | ## 多文档 API 13 | 14 | - [多重获取](/rest_apis/document_apis/multi_get) 15 | - [批量](/rest_apis/document_apis/bulk) 16 | - [按查询删除](/rest_apis/document_apis/delete_by_query) 17 | - [按查询更新](/rest_apis/document_apis/update_by_query) 18 | - [重索引](/rest_apis/document_apis/reindex) 19 | 20 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs.html) 21 | -------------------------------------------------------------------------------- /docs/rest_apis/document_apis/multi_termvectors.md: -------------------------------------------------------------------------------- 1 | # 多词向量 API 2 | 3 | 只需一次请求即可检索多个词(term)向量。 4 | 5 | ```bash 6 | POST /_mtermvectors 7 | { 8 | "docs": [ 9 | { 10 | "_index": "my-index-000001", 11 | "_id": "2", 12 | "term_statistics": true 13 | }, 14 | { 15 | "_index": "my-index-000001", 16 | "_id": "1", 17 | "fields": [ 18 | "message" 19 | ] 20 | } 21 | ] 22 | } 23 | ``` 24 | 25 | ## 请求 26 | 27 | `POST /_mtermvectors` 28 | 29 | `POST //_mtermvectors` 30 | 31 | ## 前置条件 32 | 33 | - 如果启用了 Elasticsearch 安全功能,则必须拥有目标索引或索引别名的 `read` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 34 | 35 | ## 描述 36 | 37 | 你可以通过索引和 ID 指定现有文档,也可以在请求正文中提供人工文档。你可以在请求体或请求 URI 中指定索引。 38 | 39 | 响应包含一个 `docs` 数组,其中包含所有获取的词向量。每个元素都有[词向量](/rest_apis/document_apis/termvectors) API 提供的结构。 40 | 41 | 有关可包含在响应中的信息的更多信息,参阅[词向量](/rest_apis/document_apis/termvectors) API。 42 | 43 | ## 路径参数 44 | 45 | - `` 46 | 47 | (可选,字符串)包含文件的索引名称。 48 | 49 | ## 查询参数 50 | 51 | - `fields` 52 | 53 | (可选,字符串) 用逗号分隔的字段列表或通配符表达式,这些字段将包含在统计信息中。 54 | 55 | 除非在 `completion_fields` 或 `fielddata_fields` 参数中提供了特定字段列表,否则将作为默认列表使用。 56 | 57 | - `field_statistics` 58 | 59 | (可选,布尔值) 如果为 `true`,响应将包括文档计数、文档频率总和以及词总频率总和。默认为 `true`。 60 | 61 | - `` 62 | 63 | (可选,布尔值) 如果为 `true`,则响应包括词偏移。默认为 `true`。 64 | 65 | - `payloads` 66 | 67 | (可选,布尔值) 如果为 `true`,则响应包括词有效载荷。默认为 `true`。 68 | 69 | - `positions` 70 | 71 | (可选,布尔值) 如果为 `true`,则响应包括词位置。默认为 `true`。 72 | 73 | - `preference` 74 | 75 | (可选,字符串) 指定应在哪个节点或分片上执行操作。默认为随机。 76 | 77 | - `routing` 78 | 79 | (可选,字符串) 用于将操作路由到特定分区的自定义值。 80 | 81 | - `realtime` 82 | 83 | (可选,布尔值) 如果为 `true`,则表示请求是实时的,而不是近实时的。默认为 `true`。参阅[实时](/docs/rest_apis/document_apis/get#实时)。 84 | 85 | - `term_statistics` 86 | 87 | (可选,布尔值)如果为 `true`,则响应包括词频和文档频率。默认为 `false`。 88 | 89 | - `version` 90 | 91 | (可选,布尔值) 如果为 `true`,则返回作为命中一部分的文档版本。 92 | 93 | - `version_type` 94 | 95 | (可选,枚举值) 特定版本类型:`external`、`external_gte`。 96 | 97 | ### 示例 98 | 99 | 如果在请求 URI 中指定索引,则无需为请求体中的每个文档指定索引: 100 | 101 | ```bash 102 | POST /my-index-000001/_mtermvectors 103 | { 104 | "docs": [ 105 | { 106 | "_id": "2", 107 | "fields": [ 108 | "message" 109 | ], 110 | "term_statistics": true 111 | }, 112 | { 113 | "_id": "1" 114 | } 115 | ] 116 | } 117 | ``` 118 | 119 | 如果请求的所有文件都在同一索引中,且参数相同,则可使用以下简化语法: 120 | 121 | ```bash 122 | POST /my-index-000001/_mtermvectors 123 | { 124 | "ids": [ "1", "2" ], 125 | "parameters": { 126 | "fields": [ 127 | "message" 128 | ], 129 | "term_statistics": true 130 | } 131 | } 132 | ``` 133 | 134 | ### 人工文档 135 | 136 | 你还可以使用 `mtermvectors` 为请求体中提供的人工文档生成词向量。使用的映射由指定的 `_index` 决定。 137 | 138 | ```bash 139 | POST /_mtermvectors 140 | { 141 | "docs": [ 142 | { 143 | "_index": "my-index-000001", 144 | "doc" : { 145 | "message" : "test test test" 146 | } 147 | }, 148 | { 149 | "_index": "my-index-000001", 150 | "doc" : { 151 | "message" : "Another test ..." 152 | } 153 | } 154 | ] 155 | } 156 | ``` 157 | 158 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html) 159 | -------------------------------------------------------------------------------- /docs/rest_apis/document_apis/optimistic_concurrency_control.md: -------------------------------------------------------------------------------- 1 | # 乐观并发控制 2 | 3 | Elasticsearch 是分布式的。当创建、更新或删除文档时,文档的新版本必须复制到集群中的其他节点。Elasticsearch 也是异步和并发的,这意味着这些复制请求是并行发送的,而且可能会不按顺序到达目的地。Elasticsearch 需要一种方法来确保文档的旧版本永远不会覆盖新版本。 4 | 为了确保文档的旧版本不会覆盖新版本,对文档执行的每次操作都会由负责协调更改的主分片分配一个序列号。每次操作都会增加序列号,因此较新操作的序列号会高于较旧操作的序列号。然后,Elasticsearch 可以使用操作的序列号来确保较新的文档版本不会被分配给它的序列号较小的变更所覆盖。 5 | 6 | 例如,下面的索引命令将创建一个文档,并为其分配一个初始序列号和主要词: 7 | 8 | ```bash 9 | PUT products/_doc/1567 10 | { 11 | "product" : "r2d2", 12 | "details" : "A resourceful astromech droid" 13 | } 14 | ``` 15 | 16 | 你可以在响应的 `_seq_no` 和 `_primary_term` 字段中看到分配的序列号和主要词: 17 | 18 | ```json 19 | { 20 | "_shards": { 21 | "total": 2, 22 | "failed": 0, 23 | "successful": 1 24 | }, 25 | "_index": "products", 26 | "_id": "1567", 27 | "_version": 1, 28 | "_seq_no": 362, 29 | "_primary_term": 2, 30 | "result": "created" 31 | } 32 | ``` 33 | 34 | Elasticsearch 会记录上次更改其存储的每个文档的操作的序列号和主要词。序列号和主要词会在 [获取 API](/rest_apis/document_apis/get) 响应的 `_seq_no` 和 `_primary_term` 字段中返回: 35 | 36 | ```bash 37 | GET products/_doc/1567 38 | ``` 39 | 40 | 返回: 41 | 42 | ```json 43 | { 44 | "_index": "products", 45 | "_id": "1567", 46 | "_version": 1, 47 | "_seq_no": 362, 48 | "_primary_term": 2, 49 | "found": true, 50 | "_source": { 51 | "product": "r2d2", 52 | "details": "A resourceful astromech droid" 53 | } 54 | } 55 | ``` 56 | 57 | 注意:通过设置 [`seq_no_primary_term` 参数](/rest_apis/search_apis/search),搜索 API 可以返回每个搜索结果的 `_seq_no` 和 `_primary_term`。 58 | 59 | 序列号和主要术语可唯一标识一项更改。通过记下返回的序列号和主要术语,可以确保只有在检索后没有其他更改的情况下才更改文档。这可以通过设置[索引 API](/rest_apis/document_apis/docs_index)、[更新 API](/rest_apis/document_apis/update) 或[删除 API](/rest_apis/document_apis/delete) 的 `if_seq_no` 和 `if_primary_term` 参数来实现。 60 | 61 | 例如,下面的索引调用将确保在文档中添加一个标签,而不会丢失描述的任何潜在更改或其他 API 添加的另一个标签: 62 | 63 | ```bash 64 | PUT products/_doc/1567?if_seq_no=362&if_primary_term=2 65 | { 66 | "product": "r2d2", 67 | "details": "A resourceful astromech droid", 68 | "tags": [ "droid" ] 69 | } 70 | ``` 71 | 72 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/optimistic-concurrency-control.html) 73 | -------------------------------------------------------------------------------- /docs/rest_apis/document_apis/refresh.md: -------------------------------------------------------------------------------- 1 | # ?refresh 2 | 3 | [索引](rest_apis/document_apis/docs_index)、[更新](rest_apis/document_apis/update)、[删除](rest_apis/document_apis/delete)和[批量](rest_apis/document_apis/bulk) API 支持设置 `refresh`,以控制搜索何时可以看到该请求所做的更改。这些是允许的值: 4 | 5 | - **空字符串**或 `true` 6 | 7 | 在操作发生后立即刷新相关的主分片和副本分片(而不是整个索引),以便更新后的文档立即出现在搜索结果中。**只有**在经过深思熟虑并确认不会导致索引和搜索性能低下的情况下,才可以这样做。 8 | 9 | - `wait_for` 10 | 11 | 在响应之前,等待请求所做的更改通过刷新变得可见。这不会强制立即刷新,而是等待刷新发生。Elasticsearch 会每隔 `index.refresh_interval`(默认值为一秒)自动刷新一次已更改的分片。该设置是[动态的](index_modules/index_module#动态索引设置)。调用[刷新](rest_apis/index_apis/refresh) API 或在任何支持刷新的 API 上将 `refresh` 设置为 `true` 也会导致刷新,进而导致已经在运行的 `refresh=wait_for` 请求返回。 12 | 13 | - `false`(默认值) 14 | 15 | 不采取任何与刷新相关的操作。该请求所做的更改将在请求返回后的某个时间点可见。 16 | 17 | ## 选用哪个设置 18 | 19 | 除非你有充分的理由等待更改变得可见,否则请始终使用 `refresh=false`(默认设置)。最简单快捷的选择是从 URL 中省略 `refresh` 参数。 20 | 21 | 如果绝对必须让请求所做的更改与请求同步可见,则必须在增加 Elasticsearch 负载(`true`)和延长响应等待时间(`wait_for`)之间做出选择。以下几点可以帮助你做出决定: 22 | 23 | - 索引更改的次数越多,`wait_for` 与 `true` 相比节省的工作量就越多。如果索引每隔一次 `index.refresh_interval` 才更改一次,那么 `wait_for` 不会节省任何工作。 24 | 25 | - `true` 会创建效率较低的索引结构(小段),这些小段随后必须合并到效率更高的索引结构(大段)中。也就是说,`true` 的代价是在创建索引时创建小段,在搜索时搜索小段,以及在合并时创建大段。 26 | 27 | - 切勿连续启动多个 `refresh=wait_for` 请求。相反,使用 `refresh=wait_for` 将它们批量合并为一个批量请求,Elasticsearch 会并行启动所有请求,并在所有请求都完成后才返回。 28 | 29 | - 如果将刷新间隔设为 `-1`,禁用自动刷新,那么使用 `refresh=wait_for` 的请求将无限期等待,直到某个操作导致刷新。相反,将 `index.refresh_interval` 设置为比默认值更短的值,如 `200ms`,会使 `refresh=wait_for` 的刷新速度更快,但仍会产生低效的分段。 30 | 31 | - `refresh=wait_for` 只影响它所在的请求,但通过强制立即刷新,`refresh=true` 会影响其他正在进行的请求。通常,如果你有一个正在运行的系统,你不想打扰它,那么 `refresh=wait_for` 是一个较小的修改。 32 | 33 | ## `refresh=wait_for` 能强制刷新 34 | 35 | 如果在分片上已经有 `index.max_refresh_listeners`(默认值为 `1000`)请求在等待刷新时,收到了 `refresh=wait_for` 请求,那么该请求的行为将与刷新设置为 `true` 时的行为一样:它将强制刷新。这样做既能保证 `refresh=wait_for` 请求返回时,其变更对搜索是可见的,又能防止被阻塞的请求不经检查而占用资源。如果一个请求因为用完了监听器槽而强制刷新,那么它的响应将包含 `"forced_refresh":true`。 36 | 37 | 无论批量请求修改了多少次分区,它们在每个分区上都只占用一个槽位。 38 | 39 | ## 示例 40 | 41 | 这将创建一个文档,并立即刷新索引,使其可见: 42 | 43 | ```bash 44 | PUT /test/_doc/1?refresh 45 | {"test": "test"} 46 | PUT /test/_doc/2?refresh=true 47 | {"test": "test"} 48 | ``` 49 | 50 | 这将创建一个文档,但不会使其在搜索时可见: 51 | 52 | ```bash 53 | PUT /test/_doc/3 54 | {"test": "test"} 55 | PUT /test/_doc/4?refresh=false 56 | {"test": "test"} 57 | ``` 58 | 59 | 这将创建一个文档,并等待它在搜索时可见: 60 | 61 | ```bash 62 | PUT /test/_doc/4?refresh=wait_for 63 | {"test": "test"} 64 | ``` 65 | 66 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-refresh.html) 67 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/alias_exists.md: -------------------------------------------------------------------------------- 1 | # 别名存在 API 2 | 3 | 检查一个[别名](/aliases)是否存在。 4 | 5 | ```bash 6 | HEAD _alias/my-alias 7 | ``` 8 | 9 | ## 请求 10 | 11 | `HEAD _alias/` 12 | 13 | `HEAD /_alias/` 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你必须对索引有 `view_index_metadata` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。如果你指定一个目标,你必须对目标也有 `view_index_metadata` 或 `manage` 索引权限。 18 | 19 | ## 路径参数 20 | 21 | - `` 22 | 23 | (可选,字符串)以逗号分隔的待检查的别名列表。支持通配符(*)。 24 | 25 | - `` 26 | 27 | (可选,字符串)用于限制请求的,逗号分隔的数据流或索引。 28 | 29 | ## 查询参数 30 | 31 | - `expand_wildcards` 32 | 33 | (可选,字符串)通配符表达式可以匹配的索引类型。如果请求可以数据流为目标,则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 `open,hidden`。有效的值有: 34 | 35 | 1. `all` 36 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 37 | 2. `open` 38 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 39 | 3. `closed` 40 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 41 | 4. `hidden` 42 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 43 | 5. `none` 44 | 不接受通配符表达式。 45 | 46 | 默认为 `all`。 47 | 48 | - `ignore_unavailable` 49 | 50 | (可选,布尔值)如果为 `true`,丢失的或关闭的索引不包含在响应中。默认为 `false`。 51 | 52 | - `local` 53 | 54 | (可选,布尔值)如果为 `true`,请求只从本地节点获取信息。默认为 `false`,意味着信息从主节点获取。 55 | 56 | ## 响应码 57 | 58 | - `200` 59 | 60 | 所有指定的别名都存在。 61 | 62 | - `404` 63 | 64 | 一个或多个指定的别名不存在。 65 | 66 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-alias-exists.html) 67 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/clear_cache.md: -------------------------------------------------------------------------------- 1 | # 清除缓存 API 2 | 3 | 清除一个或多个索引的缓存。对于数据流,API 清除流的备份索引的缓存。 4 | 5 | ```bash 6 | POST /my-index-000001/_cache/clear 7 | ``` 8 | 9 | ## 请求 10 | 11 | `POST //_cache/clear` 12 | 13 | `POST /_cache/clear` 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你使用此 API 必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 18 | 19 | ## 路径参数 20 | 21 | - `` 22 | 23 | (可选,字符串)限制请求的逗号分隔的数据流、索引和别名的列表。支持通配符(*)。要以所有数据流和索引为目标,忽略此参数或使用 `*` 或 `_all`。 24 | 25 | ## 查询参数 26 | 27 | - `allow_no_indices` 28 | 29 | (可选,布尔值)如果为 `false`,任何通配符、[索引别名](/rest_apis/index_apis/bulk_index_alias)或 `_all` 值只针对丢失或关闭的索引,请求将返回一个错误。即使请求以其他开启索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,而没有索引以 `bar` 开头,则以 `foo*,bar*` 为目标的请求将返回错误。 30 | 31 | 默认为 `true`。 32 | 33 | - `expand_wildcards` 34 | 35 | (可选,字符串)通配符表达式可以匹配的索引类型。如果请求可以数据流为目标,则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 `open,hidden`。有效的值有: 36 | 37 | 1. `all` 38 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 39 | 2. `open` 40 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 41 | 3. `closed` 42 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 43 | 4. `hidden` 44 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 45 | 5. `none` 46 | 不接受通配符表达式。 47 | 48 | 默认为 `open`。 49 | 50 | - `fielddata` 51 | 52 | (可选,布尔值)如果为 `true`,清除字段缓存。 53 | 54 | 使用 `fields` 字段仅清除特定字段的缓存。 55 | 56 | - `fields` 57 | 58 | (可选,字符串)逗号分隔用于限制 `fielddata` 参数的字段名字列表。 59 | 60 | 默认为所有字段。 61 | 62 | :::note 提示 63 | 此参数**不**支持对象或字段别名。 64 | ::: 65 | 66 | - `index` 67 | 68 | (可选,字符串)用于限制请求的,逗号分隔的索引名字。 69 | 70 | - `ignore_unavailable` 71 | 72 | (可选,布尔值)如果为 `true`,丢失或关闭的索引不包含在响应中。 73 | 74 | 默认为 `false`。 75 | 76 | - `query` 77 | 78 | (可选,布尔值)如果为 `true`,清除查询缓存。 79 | 80 | - `request` 81 | 82 | (可选,布尔值)如果为 `true`,清除请求缓存。 83 | 84 | ## 示例 85 | 86 | ### 清除指定缓存 87 | 88 | 默认情况,清除缓存 API 清除所有缓存。你可以通过以下以下查询参数为 `true` 来清除指定缓存: 89 | 90 | - `fielddata` 91 | - `query` 92 | - `request` 93 | 94 | ```bash 95 | POST /my-index-000001/_cache/clear?fielddata=true 96 | POST /my-index-000001/_cache/clear?query=true 97 | POST /my-index-000001/_cache/clear?request=true 98 | ``` 99 | 100 | 1. 第一个请求,仅清除字段缓存 101 | 2. 第二个请求,仅清除查询缓存 102 | 3. 第三个请求,仅清除请求缓存 103 | 104 | ### 清除指定字段缓存 105 | 106 | 为了只清除指定指定字段缓存,使用 `fields` 查询参数: 107 | 108 | ```bash 109 | POST /my-index-000001/_cache/clear?fields=foo,bar 110 | ``` 111 | 112 | 1. 此请求清除字段 `foo` 和 `bar` 的缓存 113 | 114 | ### 清除所有数据流和索引的缓存 115 | 116 | ```bash 117 | POST /_cache/clear 118 | ``` 119 | 120 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-clearcache.html) 121 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/clone_index.md: -------------------------------------------------------------------------------- 1 | # 复制索引 2 | 3 | 复制一个现有索引 4 | 5 | ```bash 6 | POST /my-index-000001/_clone/cloned-my-index-000001 7 | ``` 8 | 9 | ## 请求 10 | 11 | `POST //_clone/` 12 | 13 | `PUT //_clone/` 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你对目标索引必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 18 | - 为了复制索引,索引必须标记为只读,并且[集群健康](/rest_apis/cluster_apis/cluster_health)状态为 `green`(绿色)。 19 | 20 | 例如,以下请求在 `` 上阻止写操作,所以它就能被复制。元数据变更,比如删除索引仍然是允许的。 21 | 22 | ```bash 23 | PUT /my_source_index/_settings 24 | { 25 | "settings": { 26 | "index.blocks.write": true 27 | } 28 | } 29 | ``` 30 | 31 | 在数据流的当前写索引不能被复制。为了复制当前写索引,这个数据流必须先被[翻转](/data_streams/data_streams#翻转),这样一个新的写索引被创建,前一个写索引才能被复制。 32 | 33 | ## 描述 34 | 35 | 使用复制索引 API 来复制现有索引到一个新的索引,现有索引的每个源主分片也会复制到新索引的新主分片中。 36 | 37 | ### 复制的原理 38 | 39 | 复制按以下步骤进行: 40 | 41 | - 首先,它创建一个与源索引定义一样的新的目标索引。 42 | - 接着,从源索引硬连接 segment(段)到目标索引。(如果文件系统不支持硬连接,那么所有的 segment(段)都会复制到新索引中,这是一个非常耗时的过程) 43 | - 最后,恢复目标索引,就像刚被重新打开的关闭索引一样。 44 | 45 | ### 复制一个索引 46 | 47 | 为了将 `my_source_index` 复制为新的索引 `my_target_index`,执行以下请求: 48 | 49 | ```bash 50 | POST /my_source_index/_clone/my_target_index 51 | ``` 52 | 53 | 一旦将目标索引添加到集群状态,上述请求将立即返回——它不会等待复制操作开始。 54 | 55 | :::caution 警告 56 | 索引只有满足以下要求才能被复制: 57 | 58 | - 目标索引不存在 59 | - 源索引的主分片数与目标索引一致 60 | - 处理复制进程的节点必须有足够的可用磁盘空间来容纳现有索引的第二个副本 61 | ::: 62 | `_clone` API 类似[创建索引 API](/rest_apis/index_apis/create_index),也为目标索引接受参数 `settings` 和 `aliases`: 63 | 64 | ```bash 65 | POST /my_source_index/_clone/my_target_index 66 | { 67 | "settings": { 68 | "index.number_of_shards": 5 69 | }, 70 | "aliases": { 71 | "my_search_indices": {} 72 | } 73 | } 74 | ``` 75 | 76 | 1. *"index.number_of_shards": 5* 目标索引的分片数。必须与源索引分片数相同。 77 | 78 | > 在 `_clone` 请求中,可以不指定映射(mapping)。源索引的映射将用于目标索引。 79 | 80 | ### 监控复制过程 81 | 82 | 监控过程可以通过 [`_cat recovery` API](/rest_apis/compact_and_aligned_text_apis/cat_recovery.html) 监控,,或使用 [`集群健康` API](/rest_apis/cluster_apis/cluster_health) 通过 `wait_for_status` 参数设置为 `yellow`(黄色)等待所有主分片成功分配。 83 | 84 | `_clone` API 一旦目标索引被添加到集群的状态,在任何分片被分配前,就会返回结果。这时,所有的分片都处于 `unassigned`(未分配)状态。如果由于任一原因,目标索引不能分配,它的主分片会保持 `unassigned` 直到它能在节点上分配。 85 | 86 | 一旦主节点被分配了,它的状态会变为 `initializing`(初始化中),拆分过程开始。当拆分操作完成,分片会变为 `active`(激活)。这时,Elasticsearch 会尝试分配任何副本,并可能决定主分片重定位到另一个节点。 87 | 88 | ### 等待活动分片 89 | 90 | 由于拆分操作创建一个新索引来拆分分片进去,所以在索引创建的设置[等待活动分片](/index_apis/create_index#等待活动分片)也应用于拆分索引操作。 91 | 92 | ## 路径参数 93 | 94 | - `` 95 | 96 | (必需,字符串)待复制的源索引名字 97 | 98 | - `` 99 | 100 | (必需,字符串)创建的目标索引名字 101 | 102 | 索引名字必须符合以下约定: 103 | 104 | 1. 只能是小写字符 105 | 2. 不能包含字符:`\`、`/`、`*`、`?`、`"`、`<`、`>`、`|`、` `(空格)、`,`、`#` 106 | 3. 7.0 之前索引可以包含冒号(:),但在 7.0 之后不推荐。 107 | 4. 不能以 `-`、`_`、`+` 开头 108 | 5. 不能是 `.` 或 `..` 109 | 6. 长度不能超过 255 字节(注意是字节,所以多字节字符会更快达到 255 的限制) 110 | 7. 名字以 `.` 开头不推荐,除非由插件管理的[隐藏索引](/index_modules)和内部索引 111 | 112 | ## 查询参数 113 | 114 | - `wait_for_active_shards` 115 | (可选,字符串)在操作执行之前必须活动的分片复制数量。设置为 `all` 或任何正整数,最大值为索引分片总数(`number_of_replicas+1`)。默认为:1,主分片。 116 | 117 | - `master_timeout` 118 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 119 | 120 | - `timeout` 121 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 122 | 123 | ## 请求体 124 | 125 | - `aliases` 126 | 127 | (可选,[别名对象](/rest_apis/idnex_apis/bulk_index_alias))包含目标索引的索引别名。参阅[批量索引别名](/rest_apis/idnex_apis/bulk_index_alias)。 128 | 129 | - `settings` 130 | 131 | (可选,[索引设置对象](/index_modules#索引设置))目标索引配置选项。参阅[索引设置](/index_modules#索引设置)。 132 | 133 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-clone-index.html) 134 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/close_index.md: -------------------------------------------------------------------------------- 1 | # 关闭索引 API 2 | 3 | 关闭一个索引。 4 | 5 | ```bash 6 | POST /my-index-000001/_close 7 | ``` 8 | 9 | ## 请求 10 | 11 | `POST //_close` 12 | 13 | ## 前置条件 14 | 15 | - 如果 Elasticsearch 安全特性启用,你对目标索引必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 16 | 17 | ## 描述 18 | 19 | 你使用关闭索引 API 来关闭开启的索引。 20 | 21 | 关闭的索引被阻止进行读/写操作,并且不允许开启的索引允许的所有操作。在关闭的索引中不能索引文档或搜索文档。这允许关闭的索引不必维护索引或搜索文档的内部数据结构,以减少集群的开销。 22 | 23 | 当打开或关闭索引时,主节点负责重新启动索引分片以反映索引的新状态。分片将经过正常的恢复过程。打开的/关闭的索引数据由集群自动复制,以确保始终安全地保留足够的分片副本。 24 | 25 | 你可以打开和关闭多个索引。如果请求显示引用缺失的索引,会抛出错误。这个行为可以通用 `ignore_unavailable=true` 参数禁用。 26 | 27 | 所有索引可以通过 `_all` 作为索引名字或指定标识所有索引模式(如 `*`)来一次打开或关闭。 28 | 29 | 在配置文件中通过设置 `action.destructive_requires_name` 标识为 `true`,可以禁用通过通配符或 `_all` 来定义所有索引。这个设置也可以通过集群更新设置 API 来修改。 30 | 31 | 关闭的索引会消耗显著数量的硬盘空间,这在托管环境中可能会造成问题。通过集群设置 API 将 `cluster.indices.close.enable` 设置为 `false`,可以禁用关闭索引。默认值为 `true`。 32 | 33 | 在7.12.0及更早版本中,无法关闭数据流上的当前写入索引。为了关闭当前写索引,数据流必须先被[翻转](/data_streams/data_streams#翻转)以便创建新的写入索引,这样之前的写入索引能被关闭。此限制从 7.12.1 不再适用。 34 | 35 | ## 路径参数 36 | 37 | - `` 38 | 39 | (可选,字符串)用于限制请求的,逗号分隔的数据流、索引。 40 | 41 | 使用 `_all` 或 `*` 关闭所有索引。修改 `action.destructive_requires_name` 集群设置为 `true`,可以禁用通过 `_all` 或 `*` 关闭索引。你可以在文件 `elasticsearch.yml` 中 或通过 [集群更新设置](/rest_apis/cluster_apis/cluster_update_settings.html) API 来更新这个设置。 42 | 43 | ## 查询参数 44 | 45 | - `allow_no_indices` 46 | 47 | (可选,布尔值)如果为 `false`,如果任何通配符表达式、索引别名或 `_all` 值只针对丢失或关闭的索引,则请求返回一个错误。即使请求以其他开放索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,但没有索引以 `bar` 开头,以 `foo*,bar*` 为目标的请求将返回错误。 48 | 49 | 默认为 `true`。 50 | 51 | - `expand_wildcards` 52 | 53 | (可选,字符串)通配符表达式能匹配的索引类型。如果请求目标为数据流,则此参数确定通配符表达式是否匹配隐藏的数据流则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔列表的值,如 `open,hidden`。有效的值有: 54 | 55 | 1. `all` 56 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 57 | 2. `open` 58 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 59 | 3. `closed` 60 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 61 | 4. `hidden` 62 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 63 | 5. `none` 64 | 不接受通配符表达式。 65 | 66 | 默认为 `open`。 67 | 68 | - `ignore_unavailable` 69 | (可选,布尔值)如果为 `true`,丢失的或关闭的索引不包含在响应中。默认为 `false`。 70 | 71 | - `wait_for_active_shards` 72 | (可选,字符串)在操作执行之前必须活动的分片复制数量。设置为 `all` 或任何正整数,最大值为索引分片总数(`number_of_replicas+1`)。值 `index-setting` 指依据索引设置 `index.write.wait_for_active_shards` 等待。默认:`0`,意味着不等待任何分片准备。 73 | 74 | 参阅[活动分片](/rest_apis/document_apis/docs_index#活动分片)。 75 | 76 | - `master_timeout` 77 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 78 | 79 | - `timeout` 80 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 81 | 82 | ## 示例 83 | 84 | 以下例子展示如何关闭一个索引: 85 | 86 | ```bash 87 | POST /my-index-000001/_close 88 | ``` 89 | 90 | API 返回以下响应: 91 | 92 | ```json 93 | { 94 | "acknowledged": true, 95 | "shards_acknowledged": true, 96 | "indices": { 97 | "my-index-000001": { 98 | "closed": true 99 | } 100 | } 101 | } 102 | ``` 103 | 104 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-close.html) 105 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/create_or_update_index_alias.md: -------------------------------------------------------------------------------- 1 | # 创建或更新索引别名 API 2 | 3 | 创建或更新索引别名。 4 | 5 | 索引别名是一个或多个索引的第二个名字。大多数 Elasticsearch API 都支持索引别名代替索引名称。 6 | 7 | ```bash 8 | PUT /my-index-000001/_alias/alias1 9 | ``` 10 | 11 | ## 请求 12 | 13 | `PUT //_alias/` 14 | 15 | `POST //_alias/` 16 | 17 | `PUT //_aliases/` 18 | 19 | `POST //_aliases/` 20 | 21 | ## 前置条件 22 | 23 | - 如果 Elasticsearch 安全特性启用,你对所有索引和索引别名必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 24 | 25 | ## 路径参数 26 | 27 | - `` 28 | 29 | (必需的,字符串)待添加别名的,逗号分隔列表或通配符的索引名。 30 | 31 | 为了向集群中的所有索引添加别名,使用值 `_all`。 32 | 33 | :::note 提示 34 | 你不能给[数据流](/datastreams/datastreams)添加索引别名。 35 | ::: 36 | 37 | - `` 38 | 39 | (必需的,字符串)待创建或升级的索引别名的名字。支持[日期数学](/rest_apis/api_convention/date_math_support_in_index_names)。 40 | 41 | ## 查询参数 42 | 43 | - `master_timeout` 44 | 45 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 46 | 47 | - `timeout` 48 | 49 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 50 | 51 | ## 请求体 52 | 53 | - `filter` 54 | 55 | (可选,查询对象)[过滤器查询](/query_dsl/compound_queries/boolean)用于限制索引别名。 56 | 如果指定,索引别名仅用于过滤器返回的文档。 57 | 58 | - `routing` 59 | 60 | (可选,字符串)用于路由操作到指定分片的自定义值。 61 | 62 | ## 示例 63 | 64 | 索引别名支持[日期数学](/rest_apis/api_convention/date_math_support_in_index_names)。 65 | 66 | ### 添加一个基于时间的别名 67 | 68 | 以下的请求为索引 `logs_20302801` 创建一个别名 `2030`。 69 | 70 | ```bash 71 | PUT /logs_20302801/_alias/2030 72 | ``` 73 | 74 | ### 添加一个基于用户的别名 75 | 76 | 首先,创建一个带有 `user_id` 字段映射的索引 `users`: 77 | 78 | ```bash 79 | PUT /users 80 | { 81 | "mappings" : { 82 | "properties" : { 83 | "user_id" : {"type" : "integer"} 84 | } 85 | } 86 | } 87 | ``` 88 | 89 | 接着,为特定用户 `user_12` 添加索引别名: 90 | 91 | ```bash 92 | PUT /users/_alias/user_12 93 | { 94 | "routing" : "12", 95 | "filter" : { 96 | "term" : { 97 | "user_id" : 12 98 | } 99 | } 100 | } 101 | ``` 102 | 103 | ### 在索引创建时添加一个别名 104 | 105 | 你可以使用[创建索引 API](/rest_apis/index_apis/create_index)在索引创建时添加一个索引别名。 106 | 107 | ```bash 108 | PUT /logs_20302801 109 | { 110 | "mappings": { 111 | "properties": { 112 | "year": { "type": "integer" } 113 | } 114 | }, 115 | "aliases": { 116 | "current_day": {}, 117 | "2030": { 118 | "filter": { 119 | "term": { "year": 2030 } 120 | } 121 | } 122 | } 123 | } 124 | ``` 125 | 126 | 创建索引 API 在索引别名的名字中也支持[日期数学](/rest_apis/api_convention/date_math_support_in_index_names)。 127 | 128 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-add-alias.html) 129 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/delete_component_template.md: -------------------------------------------------------------------------------- 1 | # 删除组件模板 API 2 | 3 | 删除已有的组件模板。 4 | 5 | ```bash 6 | DELETE _component_template/template_1 7 | ``` 8 | 9 | 提供的 `` 可以包含多个用逗号分隔的模板名称。如果指定了多个模板名称,则不支持通配符,并且提供的名称应与现有组件模板完全匹配。 10 | 11 | ## 请求 12 | 13 | `DELETE /_component_template/` 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你使用此 API 必须有 `manage_index_templates` 或 `manage` [集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)。 18 | 19 | ## 描述 20 | 21 | 使用删除组件模板 API 可以删除一个或多个组件模板。组件模板是构造[索引模板](/index_templates/index_templates)的构造块,用于指定索引映射、设置和别名。 22 | 23 | ## 路径参数 24 | 25 | - `` 26 | 27 | (必需,字符串)用于限制请求的,逗号分隔的组件模板名字或通配符表达式。 28 | 29 | ## 查询参数 30 | 31 | - `master_timeout` 32 | 33 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 34 | 35 | - `timeout` 36 | 37 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 38 | 39 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-component-template.html) 40 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/delete_dangling_index.md: -------------------------------------------------------------------------------- 1 | # 删除悬空索引 API 2 | 3 | 删除一个悬空索引。 4 | 5 | ## 请求 6 | 7 | ```bash 8 | DELETE /_dangling/?accept_data_loss=true 9 | ``` 10 | 11 | ## 前置条件 12 | 13 | - 如果 Elasticsearch 安全特性启用,你必须有 `manage` [集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)来使用此 API。 14 | 15 | ## 描述 16 | 17 | 如果 Elasticsearch 遇到当前集群状态中缺少的索引数据,则认为这些索引处于悬空状态。例如,如果在 Elasticsearch 节点脱机时删除多个 `cluster.index.tombstones.size` 索引,则可能会发生这种情况。 18 | 19 | 通过引用其 UUID 可以删除悬空索引。使用[列出悬空索引 API](/rest_apis/index_apis/list_dangling_indices) 定位索引的 UUID。 20 | 21 | ## 路径参数 22 | 23 | - `` 24 | 25 | (必需的,字符串)待删除索引的 UUID,你可以通过[列出悬空索引 API](/rest_apis/index_apis/list_dangling_indices) 找到它。 26 | 27 | ## 查询参数 28 | 29 | - `accept_data_loss` 30 | 31 | (必需的,布尔值)此字段必须设置为 `true` 才能导入悬空索引。由于 Elasticsearch 无法知道悬空索引数据来自何处,也无法确定哪些分片副本是新的,哪些是旧的,因此它无法保证导入的数据代表索引在集群中最后一次出现时的最新状态。 32 | 33 | - `master_timeout` 34 | 35 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 36 | 37 | - `timeout` 38 | 39 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 40 | 41 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/dangling-index-delete.html) 42 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/delete_index.md: -------------------------------------------------------------------------------- 1 | # 删除索引 API 2 | 3 | 删除已有的索引。 4 | 5 | ```bash 6 | DELETE /my-index-000001 7 | ``` 8 | 9 | ## 请求 10 | 11 | `DELETE /` 12 | 13 | ## 前置条件 14 | 15 | - 如果 Elasticsearch 安全特性启用,你对目标索引必须有 `delete_index` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 16 | 17 | ## 路径参数 18 | 19 | - `` 20 | 21 | (必需的,字符串)待删除的索引的逗号分隔列表或通配符表达式。 22 | 23 | 在这个参数中,通配符表达式只能匹配开启、具体的索引。你不能通过[别名](/rest_apis/index_apis/bulk_index_alias)删除索引。 24 | 25 | 为了删除所有索引,使用 `_all` 或 `*`。为了禁止使用 `_all` 或通配符表达式删除索引,修改 `action.destructive_requires_name` 集群设置为 `true`。你可以在 `elasticsearch.yml` 文件中或通过[集群更新](/rest_apis/cluster_apis/cluster_update_settings.html) API 更新设置。 26 | 27 | :::note 提示 28 | 你不能删除数据流的当前写入索引。为了删除索引,你必须[翻转](/data_streams/data_streams#翻转)数据流,这样一个新的写索引就创建了。这时你就可以使用删除索引 API 删除之前的写索引。 29 | ::: 30 | 31 | ## 查询参数 32 | 33 | - `allow_no_indices` 34 | 35 | (可选,布尔值)如果为 `false`,如果任何通配符表达式、索引别名或 `_all` 值只针对丢失或关闭的索引,则请求返回一个错误。即使请求以其他开放索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,但没有索引以 `bar` 开头,以 `foo*,bar*` 为目标的请求将返回错误。 36 | 37 | 默认为 `true`。 38 | 39 | - `expand_wildcards` 40 | 41 | (可选,字符串)通配符表达式能匹配的索引类型。如果请求目标为数据流,则此参数确定通配符表达式是否匹配隐藏的数据流则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔列表的值,如 `open,hidden`。有效的值有: 42 | 43 | 1. `all` 44 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 45 | 2. `open` 46 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 47 | 3. `closed` 48 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 49 | 4. `hidden` 50 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 51 | 5. `none` 52 | 不接受通配符表达式。 53 | 54 | 默认为 `open`。 55 | 56 | - `ignore_unavailable` 57 | (可选,布尔值)如果为 `true`,丢失的或关闭的索引不包含在响应中。默认为 `false`。 58 | 59 | - `master_timeout` 60 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 61 | 62 | - `timeout` 63 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 64 | 65 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html) 66 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/delete_index_alias.md: -------------------------------------------------------------------------------- 1 | # 删除索引别名 2 | 3 | 删除现有的索引别名。 4 | 5 | 索引别名是一个或多个索引的第二个名字。大多数 Elasticsearch API 都支持索引别名代替索引名称。 6 | 7 | ```bash 8 | DELETE /my-index-000001/_alias/alias1 9 | ``` 10 | 11 | ## 请求 12 | 13 | `DELETE //_alias/` 14 | 15 | `DELETE //_aliases/` 16 | 17 | ## 前置条件 18 | 19 | - 如果 Elasticsearch 安全特性启用,你对所有索引和索引别名必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 20 | 21 | ## 路径参数 22 | 23 | - `` 24 | (必需的,字符串)用于限制请求的,逗号分隔列表或通配符的索引名。 25 | 26 | 为了包含集群中的所有索引,使用值 `_all` 或 `*`。 27 | 28 | - `` 29 | (必需的,字符串)用于限制请求的,逗号分隔列表或通配符的索引别名。 30 | 31 | 为了获取所有索引别名的信息,使用值 `_all` 或 `*`。 32 | 33 | ## 查询参数 34 | 35 | - `master_timeout` 36 | 37 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 38 | 39 | - `timeout` 40 | 41 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 42 | 43 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-alias.html) 44 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/delete_index_template.md: -------------------------------------------------------------------------------- 1 | # 删除索引模板 API 2 | 3 | 删除[索引模板](/index_templates/index_templates)。 4 | 5 | ```bash 6 | DELETE /_index_template/my-index-template 7 | ``` 8 | 9 | ## 请求 10 | 11 | `DELETE /_index_template/` 12 | 13 | `` 可以包含多个用逗号分隔的模板名字。如果指定了多个模板名字,那就不能使用通配符,并且要与已有模板名字完全一样。 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你使用此 API 必须有 `manage_index_templates` 或 `manage` [集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)。 18 | 19 | ## 描述 20 | 21 | 使用删除索引模板 API 去删除一个或多个索引模板。索引模板定义了可以自动用于新索引的[设置](/index_modules#索引设置)、[映射](/mapping/mapping)和[别名](/rest_apis/index_apis/aliases)。 22 | 23 | ## 路径参数 24 | 25 | - `` 26 | 27 | (必需,字符串)限制请求的逗号分隔的索引名字列表。支持通配符(*)。 28 | 29 | ## 查询参数 30 | 31 | - `master_timeout` 32 | 33 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 34 | 35 | - `timeout` 36 | 37 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 38 | 39 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-template.html) -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/flush.md: -------------------------------------------------------------------------------- 1 | # 冲刷 API 2 | 3 | 冲刷一个或多个数据流或索引。 4 | 5 | ```bash 6 | POST /my-index-000001/_flush 7 | ``` 8 | 9 | ## 请求 10 | 11 | `POST //_flush` 12 | 13 | `GET //_flush` 14 | 15 | `POST /_flush` 16 | 17 | `GET /_flush` 18 | 19 | ## 前置条件 20 | 21 | - 如果 Elasticsearch 安全特性启用,你对目标数据流、索引或别名必须有 `maintenance` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限) 22 | 23 | ## 描述 24 | 25 | 冲刷数据流或索引是确保当前仅存储在事务日志中的任何数据也永久存储在 Lucene 索引中的过程。重新启动时,Elasticsearch 将重放从[事务日志](/index_modules/translog)到 Lucene 索引的所有未冲刷操作,以使其恢复到重新启动前的状态。Elasticsearch 会根据需要自动触发冲刷,使用试探法权衡未冲刷事务日志的大小和执行每次冲刷的成本。 26 | 27 | 一旦每个操作被冲刷,它将永久存储在 Lucene 索引中。这可能意味着不需要在事务日志中维护它的附加副本,除非[出于其他原因保留它](/index_modules/translog#事务日志保留)。事务日志由多个文件组成,称为年代,一旦不再需要,Elasticsearch 将删除任何年代文件,从而释放磁盘空间。 28 | 29 | 也可以使用冲刷 API 触发对一个或多个索引的冲刷,尽管用户很少需要直接调用此 API。如果在索引某些文档后调用冲刷 API,则成功的响应表明 Elasticsearch 已冲刷在调用冲刷 API 之前索引的所有文档。 30 | 31 | ## 路径参数 32 | 33 | - `` 34 | 35 | (可选,字符串)限制请求的逗号分隔的数据流、索引和别名的列表。支持通配符(*)。要以所有数据流和索引为目标,忽略此参数或使用 `*` 或 `_all`。 36 | 37 | - `allow_no_indices` 38 | 39 | (可选,布尔值)如果为 `false`,任何通配符、[索引别名](/rest_apis/index_apis/bulk_index_alias)或 `_all` 值只针对丢失或关闭的索引,请求将返回一个错误。即使请求以其他开启索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,而没有索引以 `bar` 开头,则以 `foo*,bar*` 为目标的请求将返回错误。 40 | 41 | 默认为 `true`。 42 | 43 | - `expand_wildcards` 44 | 45 | (可选,字符串)通配符表达式可以匹配的索引类型。如果请求可以数据流为目标,则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 `open,hidden`。有效的值有: 46 | 47 | 1. `all` 48 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 49 | 2. `open` 50 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 51 | 3. `closed` 52 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 53 | 4. `hidden` 54 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 55 | 5. `none` 56 | 不接受通配符表达式。 57 | 58 | 默认为 `open`。 59 | 60 | - `force` 61 | 62 | (可选,布尔值)如果为 `true`,即使没有变更要提交给索引,请求也强制冲刷。默认为 `true`。 63 | 64 | 可使用此参数来参加事务日志的年代值。 65 | 66 | 此参数视为内部参数。 67 | 68 | - `ignore_unavailable` 69 | 70 | (可选,布尔值)如果为 `true`,丢失或关闭的索引不包含在响应中。 71 | 72 | 默认为 `false`。 73 | 74 | - `wait_if_ongoing` 75 | 76 | (可选,布尔值)如果为 `true`,当另一个冲刷操作运行时,冲刷操作会阻塞到执行为止。 77 | 78 | 如果为 `false`,当另一个冲刷操作运行时,请求冲刷操作时,Elasticsearch 会直接返回错误。 79 | 80 | 默认为 `true`。 81 | 82 | ## 示例 83 | 84 | ### 冲刷指定的数据流或索引 85 | 86 | ```bash 87 | POST /my-index-000001/_flush 88 | ``` 89 | 90 | ### 冲刷多个数据流和索引 91 | 92 | ```bash 93 | POST /my-index-000001,my-index-000002/_flush 94 | ``` 95 | 96 | ### 冲刷集群中所有数据流和索引 97 | 98 | ```bash 99 | POST /_flush 100 | ``` 101 | 102 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html) -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/force_merge.md: -------------------------------------------------------------------------------- 1 | # 强制合并 API 2 | 3 | 强制[合并](/index_modules/merge)一个或多个索引的分片。对数据流,API 强制合并数据流的备份索引的分片。 4 | 5 | ```bash 6 | POST /my-index-000001/_forcemerge 7 | ``` 8 | 9 | ## 请求 10 | 11 | `POST //_forcemerge` 12 | 13 | `POST /_forcemerge` 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你对目标数据流、索引或别名必须有 `maintenance` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限) 18 | 19 | ## 描述 20 | 21 | 使用强制合并 API 强制[合并](/index_modules/merge)一个或多个索引的分片。合并通过将部分片段合并在一起,减少了每个片段中的片段数,还释放了被删除文档所使用的空间。合并通常自动进行,但有时手动触发合并是有用的。 22 | 23 | :::caution 警告 24 | **只有在完成对索引的写入后,才能对其调用强制合并**。强制合并可以产生非常大的(>5GB)段,并且如果继续写入这样的索引,那么自动合并策略将永远不会考虑这些段以用于将来合并,直到它们大部分由删除的文档组成。这可能会导致索引中保留非常大的段,从而导致磁盘使用率增加和搜索性能下降。 25 | ::: 26 | 27 | ### 在强制合并期间阻塞 28 | 29 | 调用此 API ,直到合并完成都是阻塞的。如果客户端连接在完成之前丢失,则强制合并过程将在后台继续。强制合并相同索引的任何新请求也将被阻止,直到正在进行的强制合并完成。 30 | 31 | ### 强制合并多个索引 32 | 33 | 你可以通过以下目标强制将多个索引与单个请求合并: 34 | 35 | - 包含多个备份索引的一个或多个数据流 36 | 37 | - 多指标 38 | 39 | - 一个或多个别名 40 | 41 | - 集群中的所有数据流和索引 42 | 43 | 使用 [`force_merge` 线程池](/set_up_elasticsearch/configuring_elasticsearch/thread_pools)分别强制合并每个目标分片。默认情况下,每个节点只有一个强制合并线程,这意味着该节点上的碎片一次强制合并一个。如果在节点上展开 `force_merge` 线程池,则它将强制并行合并其分片。 44 | 45 | 强制合并使被合并的分片的存储空间临时增加,在 `max_num_segments` 参数设置为 `1` 的情况下,存储空间将增加一倍,因为所有的片段都需要重写为新的片段。 46 | 47 | ## 路径参数 48 | 49 | - `` 50 | 51 | (可选,字符串)限制请求的逗号分隔的数据流、索引和别名的列表。支持通配符(*)。要以所有数据流和索引为目标,忽略此参数或使用 `*` 或 `_all`。 52 | 53 | ## 查询参数 54 | 55 | - `allow_no_indices` 56 | 57 | (可选,布尔值)如果为 `false`,任何通配符、[索引别名](/rest_apis/index_apis/bulk_index_alias)或 `_all` 值只针对丢失或关闭的索引,请求将返回一个错误。即使请求以其他开启索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,而没有索引以 `bar` 开头,则以 `foo*,bar*` 为目标的请求将返回错误。 58 | 59 | 默认为 `true`。 60 | 61 | - `expand_wildcards` 62 | 63 | (可选,字符串)通配符表达式可以匹配的索引类型。如果请求可以数据流为目标,则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 `open,hidden`。有效的值有: 64 | 65 | 1. `all` 66 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 67 | 2. `open` 68 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 69 | 3. `closed` 70 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 71 | 4. `hidden` 72 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 73 | 5. `none` 74 | 不接受通配符表达式。 75 | 76 | 默认为 `open`。 77 | 78 | - `flush` 79 | 80 | (可选,布尔值)如果为 `true`,Elasticsearch 在强制合并后对索引执行刷新。默认为 `true`。 81 | 82 | - `ignore_unavailable` 83 | 84 | (可选,布尔值)如果为 `true`,丢失或关闭的索引不包含在响应中。 85 | 86 | 默认为 `false`。 87 | 88 | - `max_num_segments` 89 | 90 | (可选,整型)待合并的段数量。为了完全合并索引,设置为 `1`。默认为检查是否需要执行合并。如果是,执行它。 91 | 92 | - `only_expunge_deletes` 93 | 94 | (可选,布尔值)如果为 `true`,仅删除包含文档删除的段。默认为 `false`。 95 | 96 | 在 Lucene 中,文档不会从段中删除;只是标记为已删除。在合并过程中,将创建一个不包含这些文档删除的新段。 97 | 98 | :::note 提示 99 | 此参数**不会**覆写设置 `index.merge.policy.expunge_deletes_allowed`。 100 | ::: 101 | 102 | ## 示例 103 | 104 | ### 强制合并一个指定的数据流或索引 105 | 106 | ```bash 107 | POST /my-index-000001/_forcemerge 108 | ``` 109 | 110 | ### 强制合并多个数据流或索引 111 | 112 | ```bash 113 | POST /my-index-000001,my-index-000002/_forcemerge 114 | ``` 115 | 116 | ### 强制合并所有索引 117 | 118 | ```bash 119 | POST /_forcemerge 120 | ``` 121 | 122 | ### 数据流和基于时间的索引 123 | 124 | 强制合并对于管理数据流的旧备份索引和其他基于时间的索引非常有用,尤其是在[翻转](/rest_apis/index_apis/rollover_index)之后。在这些情况下,每个索引只在一段时间内接收索引流量。一旦索引不再接收写入,它的分片就可以强制合并到单个段中。 125 | 126 | ```bash 127 | POST /.ds-my-data-stream-2099.03.07-000001/_forcemerge?max_num_segments=1 128 | ``` 129 | 130 | 这是一个好主意,因为单段分片有时可以使用更简单、更高效的数据结构来执行搜索。 131 | 132 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html) 133 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/freeze_index.md: -------------------------------------------------------------------------------- 1 | # 冻结索引 API 2 | 3 | 冻结一个索引。 4 | 5 | ## 请求 6 | 7 | `POST //_freeze` 8 | 9 | ## 前置条件 10 | 11 | - 如果 Elasticsearch 安全特性启用,你对目标索引或索引别名必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 12 | 13 | ## 描述 14 | 15 | 已冻结的索引在集群上几乎没有开销(除了在内存中维护它的元数据)且是只读的。只读索引禁止写操作,比如 [docs-index_](/rest_apis/search_apis/suggesters#索引) 或[强制合并](/rest_apis/index_apis/force_merge)。参阅[已冻结索引](/frozen_indices/frozen_indices)和[解冻索引](/rest_apis/index_apis/unfreeze_index)。 16 | 17 | 在数据流中的当前写索引不能被冻结。为了冻结当前写索引,数据流必须先被[翻转](/data_streams/data_streams#翻转),这样一个新的写索引被创建,前一个写索引才能被冻结。 18 | 19 | :::caution 警告 20 | 冻结一个索引会在同一个 API 调用中关闭这个索引并且重新打开它。这将导致在短时间内主分片不被分配,直到再次分配主分片前集群会变为红色(red)。这个限制在未来可能被移除。 21 | ::: 22 | 23 | ## 路径参数 24 | 25 | `` 26 | 27 | (必需,字符串)标识索引。 28 | 29 | ## 示例 30 | 31 | 以下的示例冻结和解冻一个索引。 32 | 33 | ```bash 34 | POST /my-index-000001/_freeze 35 | POST /my-index-000001/_unfreeze 36 | ``` 37 | 38 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/freeze-index-api.html) 39 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/get_component_template.md: -------------------------------------------------------------------------------- 1 | # 获取组件模板 API 2 | 3 | 获取一个或多个组件模板的信息。 4 | 5 | ```bash 6 | GET /_component_template/template_1 7 | ``` 8 | 9 | ## 请求 10 | 11 | `GET /_component_template/` 12 | 13 | ## 前置条件 14 | 15 | - 如果 Elasticsearch 安全特性启用,你使用此 API 必须有 `manage_index_templates` 或 `manage` [集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)。 16 | 17 | ## 路径参数 18 | 19 | - `` 20 | 21 | (可选,字符串)用于限制请求的,逗号分隔的组件模板名字。支持通配符(*)表达式。 22 | 23 | ## 查询参数 24 | 25 | - `flat_settings` 26 | 27 | (可选,布尔值)如果为 `true`,以平面格式返回设置。默认为 `false`。 28 | 29 | - `local` 30 | 31 | (可选,布尔值)如果为 `true`,请求只从本地节点获取信息。默认为 `false`,意味着信息从主节点获取。 32 | 33 | - `master_timeout` 34 | 35 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 36 | 37 | ## 示例 38 | 39 | ### 通过通配符表达式获取组件模板 40 | 41 | ```bash 42 | GET /_component_template/temp* 43 | ``` 44 | 45 | ### 获取所有组件模板 46 | 47 | ```bash 48 | GET /_component_template 49 | ``` 50 | 51 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/getting-component-templates.html#getting-component-templates) 52 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/get_index.md: -------------------------------------------------------------------------------- 1 | # 获取索引 API 2 | 3 | 返回一个或多个索引的信息。对于数据流,API 返回有关流的支持索引的信息。 4 | 5 | ```bash 6 | GET /my-index-000001 7 | ``` 8 | 9 | :::note 提示 10 | 在 7.0.0 之前,**mappings**(映射) 定义用于包含类型名称。虽然响应中的映射不再默认包含类型名称,你仍然可以通过参数 include_type_name 请求旧的格式。更多细节,参阅[移除映射类型](/mapping/removal_of_mapping_types)。 11 | ::: 12 | 13 | ## 请求 14 | 15 | `GET /` 16 | 17 | ## 前置条件 18 | 19 | - 如果 Elasticsearch 安全特性启用,你对目标索引必须有 `view_index_metadata` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 20 | 21 | ## 路径参数 22 | 23 | - `` 24 | 25 | (必需的,字符串)用于限制请求的,逗号分隔的数据流、索引。也支持通配符表达式(*)。 26 | 27 | 若要以集群中的所有数据流和索引为目标,省略此参数或使用 `_all` 或 `*`。 28 | 29 | ## 查询参数 30 | 31 | - `allow_no_indices` 32 | 33 | (可选,布尔值)如果为 `false`,如果任何通配符表达式、索引别名或 `_all` 值只针对丢失或关闭的索引,则请求返回一个错误。即使请求以其他开放索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,但没有索引以 `bar` 开头,以 `foo*,bar*` 为目标的请求将返回错误。 34 | 35 | 默认为 `true`。 36 | 37 | - `expand_wildcards` 38 | 39 | (可选,字符串)通配符表达式能匹配的索引类型。如果请求目标为数据流,则此参数确定通配符表达式是否匹配隐藏的数据流则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔列表的值,如 `open,hidden`。有效的值有: 40 | 41 | 1. `all` 42 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 43 | 2. `open` 44 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 45 | 3. `closed` 46 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 47 | 4. `hidden` 48 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 49 | 5. `none` 50 | 不接受通配符表达式。 51 | 52 | - `flat_settings` 53 | 54 | (可选,布尔值)如果为 `true`,以平面格式返回设置。默认为 `false`。 55 | 56 | - `include_defaults` 57 | 58 | (可选,字符串)如果为 `true`,在响应中返回所有默认设置。默认为 `false`。 59 | 60 | - `include_type_name` 61 | 62 | [~~7.0.0~~开始不推荐](可选,布尔值)如果为 `true`,映射体中期望有映射类型。默认为 `false`。 63 | 64 | - `ignore_unavailable` 65 | 66 | (可选,布尔值)如果为 `true`,请求不存在的索引将返回错误。默认为 `false`。 67 | 68 | - `local` 69 | 70 | (可选,布尔值)如果为 `true`,请求只从本地节点检索信息。默认为 `false`,意味着从主节点检索信息。 71 | 72 | - `master_timeout` 73 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 74 | 75 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html) 76 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/get_index_alias.md: -------------------------------------------------------------------------------- 1 | # 获取索引别名 API 2 | 3 | 返回一个或多个索引别名的信息。 4 | 5 | 索引别名是一个或多个索引的第二个名字。大多数 Elasticsearch API 都支持索引别名代替索引名称。 6 | 7 | ```bash 8 | GET /my-index-000001/_alias/alias1 9 | ``` 10 | 11 | ## 请求 12 | 13 | `GET /_alias` 14 | 15 | `GET /_alias/` 16 | 17 | `GET //_alias/` 18 | 19 | ## 前置条件 20 | 21 | - 如果 Elasticsearch 安全特性启用,你对索引别名必须有 `view_index_metadata` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。如果你指定一个索引,你对这个索引也必须要有 `view_index_metadata` 或 `manage` 索引权限。 22 | 23 | ## 路径参数 24 | 25 | - `` 26 | 27 | (可选,字符串)用于限制请求的,逗号分隔列表或通配符的索引别名。 28 | 29 | 为了获取所有索引别名的信息,使用值 `_all` 或 `*`。 30 | 31 | - `` 32 | 33 | (可选,字符串)用于限制请求的,逗号分隔列表或通配符的索引名。 34 | 35 | ## 查询参数 36 | 37 | - `allow_no_indices` 38 | 39 | (可选,布尔值)如果为 `false`,如果任何通配符表达式、索引别名或 `_all` 值只针对丢失或关闭的索引,则请求返回一个错误。即使请求以其他开放索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,但没有索引以 `bar` 开头,以 `foo*,bar*` 为目标的请求将返回错误。 40 | 41 | 默认为 `true`。 42 | 43 | - `expand_wildcards` 44 | 45 | (可选,字符串)通配符表达式能匹配的索引类型。如果请求目标为数据流,则此参数确定通配符表达式是否匹配隐藏的数据流则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔列表的值,如 `open,hidden`。有效的值有: 46 | 47 | 1. `all` 48 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 49 | 2. `open` 50 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 51 | 3. `closed` 52 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 53 | 4. `hidden` 54 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 55 | 5. `none` 56 | 不接受通配符表达式。 57 | 58 | 默认为 `open`。 59 | 60 | - `ignore_unavailable` 61 | 62 | (可选,布尔值)如果为 `true`,请求不存在的索引将返回错误。默认为 `false`。 63 | 64 | - `local` 65 | 66 | (可选,布尔值)如果为 `true`,请求只从本地节点获取信息。默认为 `false`,意味着信息从主节点获取。 67 | 68 | ## 示例 69 | 70 | ### 获取一个索引的所有别名 71 | 72 | 你可以通过[创建索引 API](/rest_apis/index_apis/create_index)请求在索引创建时添加索引别名。 73 | 74 | 以下的创建索引 API 请求创建带有两个别名的索引 `logs_20302801`: 75 | 76 | - `current_day` 77 | - `2030`,仅返回索引 `logs_20302801` 中字段 `year` 的值为 `2030` 的文档 78 | 79 | ```bash 80 | PUT /logs_20302801 81 | { 82 | "aliases" : { 83 | "current_day" : {}, 84 | "2030" : { 85 | "filter" : { 86 | "term" : {"year" : 2030 } 87 | } 88 | } 89 | } 90 | } 91 | ``` 92 | 93 | 以下获取索引别名 API 请求返回索引 `logs_20302801` 所有别名: 94 | 95 | ```bash 96 | GET /logs_20302801/_alias/* 97 | ``` 98 | 99 | API 返回以下响应: 100 | 101 | ```bash 102 | { 103 | "logs_20302801" : { 104 | "aliases" : { 105 | "current_day" : { 106 | }, 107 | "2030" : { 108 | "filter" : { 109 | "term" : { 110 | "year" : 2030 111 | } 112 | } 113 | } 114 | } 115 | } 116 | } 117 | ``` 118 | 119 | ### 获取一个指定别名 120 | 121 | 以下的索引别名 API 请求返回别名 `2030`: 122 | 123 | ```bash 124 | GET /_alias/2030 125 | ``` 126 | 127 | API 返回以下响应: 128 | 129 | ```bash 130 | { 131 | "logs_20302801" : { 132 | "aliases" : { 133 | "2030" : { 134 | "filter" : { 135 | "term" : { 136 | "year" : 2030 137 | } 138 | } 139 | } 140 | } 141 | } 142 | } 143 | ``` 144 | 145 | ### 获取基于通配符的别名 146 | 147 | 以下的索引别名 API 请求返回以 `20` 开头的任何别名: 148 | 149 | ```bash 150 | GET /_alias/20* 151 | ``` 152 | 153 | API 返回以下响应: 154 | 155 | ```bash 156 | { 157 | "logs_20302801" : { 158 | "aliases" : { 159 | "2030" : { 160 | "filter" : { 161 | "term" : { 162 | "year" : 2030 163 | } 164 | } 165 | } 166 | } 167 | } 168 | } 169 | ``` 170 | 171 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-alias.html) 172 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/get_index_settings.md: -------------------------------------------------------------------------------- 1 | # 获取索引设置 API 2 | 3 | 返回一个或多个索引的设置信息。对数据流,此 API 为数据流的备份索引返回设置信息。 4 | 5 | ```bash 6 | GET /my-index-000001/_settings 7 | ``` 8 | 9 | ## 请求 10 | 11 | `GET //_settings` 12 | 13 | `GET //_settings/` 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你对目标数据流、索引或别名必须有 `view_index_metadata`、`monitor` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 18 | 19 | ## 路径参数 20 | 21 | - `` 22 | 23 | (可选,字符串)限制请求的逗号分隔的数据流、索引和别名的列表。支持通配符(*)。要以所有数据流和索引为目标,忽略此参数或使用 `*` 或 `_all`。 24 | 25 | - `` 26 | 27 | (可选,字符串)用于限制请求的逗号分隔的设置名字或通配符。 28 | 29 | ## 查询参数 30 | 31 | - `allow_no_indices` 32 | 33 | (可选,布尔值)如果为 `false`,如果任何通配符表达式、索引别名或 `_all` 值只针对丢失或关闭的索引,则请求返回一个错误。即使请求以其他开放索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,但没有索引以 `bar` 开头,以 `foo*,bar*` 为目标的请求将返回错误。 34 | 35 | 默认为 `true`。 36 | 37 | - `expand_wildcards` 38 | 39 | (可选,字符串)通配符表达式能匹配的索引类型。如果请求目标为数据流,则此参数确定通配符表达式是否匹配隐藏的数据流则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔列表的值,如 `open,hidden`。有效的值有: 40 | 41 | 1. `all` 42 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 43 | 2. `open` 44 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 45 | 3. `closed` 46 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 47 | 4. `hidden` 48 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 49 | 5. `none` 50 | 不接受通配符表达式。 51 | 52 | 默认为 `open`。 53 | 54 | - `flat_settings` 55 | 56 | (可选,布尔值)如果为 `true`,以平面格式返回设置。默认为 `false`。 57 | 58 | - `include_defaults` 59 | (可选,布尔值)如果为 `true`,响应包含默认的映射值。默认为 `false`。 60 | 61 | - `ignore_unavailable` 62 | 63 | (可选,布尔值)如果为 `true`,丢失的或关闭的索引不包含在响应中。默认为 `false`。 64 | 65 | - `local` 66 | 67 | (可选,布尔值)如果为 `true`,请求只从本地节点检索信息。默认为 `false`,意味着从主节点检索信息。 68 | 69 | - `master_timeout` 70 | 71 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 72 | 73 | ## 示例 74 | 75 | ### 多数据流和索引 76 | 77 | 获取索引设置 API 可以用于一次请求获取超过一个数据流或索引的设置。为了获取一个集群中所有索引的设置,你可以为 ``使用 `_all` 或 `*`。也支持通配符表达式。以下是一些示例: 78 | 79 | ```bash 80 | GET /my-index-000001,my-index-000002/_settings 81 | 82 | GET /_all/_settings 83 | 84 | GET /log_2099_*/_settings 85 | ``` 86 | 87 | ### 按名字过滤设置 88 | 89 | 返回的设置可以通过通配符匹配过滤,如下所示: 90 | 91 | ```bash 92 | GET /log_2099_-*/_settings/index.number_* 93 | ``` 94 | 95 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-settings.html) 96 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/get_index_template.md: -------------------------------------------------------------------------------- 1 | # 获取索引模板 API 2 | 3 | 返回一个或多个索引模板的信息。 4 | 5 | ```bash 6 | GET /_index_template/template_1 7 | ``` 8 | 9 | ## 请求 10 | 11 | `GET /_index_template/` 12 | 13 | ## 前置条件 14 | 15 | - 如果 Elasticsearch 安全特性启用,你使用此 API 必须有 `manage_index_templates` 或 `manage` [集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)。 16 | 17 | ## 路径参数 18 | 19 | - `` 20 | 21 | (必需,字符串)限制请求的逗号分隔的索引名字列表。支持通配符(*)。 22 | 23 | 为了获取所有索引模板,忽略此参数或使用 `*` 值。 24 | 25 | ## 查询参数 26 | 27 | - `flat_settings` 28 | 29 | (可选,布尔值)如果为 `true`,以平面格式返回设置。默认为 `false`。 30 | 31 | - `include_type_name` 32 | 33 | [~~7.0.0~~开始不推荐] (可选,布尔值)如果为 `true`,映射体中需要映射类型。默认为 `false`。 34 | 35 | - `local` 36 | 37 | (可选,布尔值)如果为 `true`,请求只从本地节点获取信息。默认为 `false`,意味着信息从主节点获取。 38 | 39 | - `master_timeout` 40 | 41 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 42 | 43 | ## 示例 44 | 45 | ### 使用通配符表达式获取索引模板 46 | 47 | ```bash 48 | GET /_index_template/temp* 49 | ``` 50 | 51 | ### 获取所有索引模板 52 | 53 | ```bash 54 | GET /_index_template 55 | ``` 56 | 57 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-template.html) -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/get_mapping.md: -------------------------------------------------------------------------------- 1 | # 获取映射 API 2 | 3 | 获取一个或多个索引的[映射定义](/mapping/mapping)。对数据流而言,此 API 获取数据流的备份索引的映射。 4 | 5 | ```bash 6 | GET /my-index-000001/_mapping 7 | ``` 8 | 9 | :::note 提示 10 | 在版本 7.0.0 之前,映射的定义用于包含类型名字。即使在请求中指定类型不被推荐,但如果设置了请求参数 `include_type_name`,仍然可以提供类型。更多细节,参阅 [移除映射类型](/mapping/removal_of_mapping_types)。 11 | ::: 12 | 13 | ## 请求 14 | 15 | `GET /_mapping` 16 | 17 | `GET //_mapping` 18 | 19 | ## 前置条件 20 | 21 | - 如果 Elasticsearch 安全特性启用,你对目标数据流、索引或索引别名必须有 `view_index_metadata` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 22 | 23 | ## 路径参数 24 | 25 | `` 26 | 27 | (可选,字符串)用于限制请求的,逗号分隔的数据流、索引和别名列表。支持通配符(*)。为了标明所有数据流和索引,省略这个参数或者使用 `*` 或 `_all`。 28 | 29 | ## 查询参数 30 | 31 | - `allow_no_indices` 32 | 33 | (可选,布尔值)如果为 `false`,如果任何通配符表达式、索引别名或 `_all` 值只针对丢失或关闭的索引,则请求返回一个错误。即使请求以其他开放索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,但没有索引以 `bar` 开头,以 `foo*,bar*` 为目标的请求将返回错误。 34 | 35 | 默认为 `true`。 36 | 37 | - `expand_wildcards` 38 | 39 | (可选,字符串)通配符表达式能匹配的索引类型。如果请求目标为数据流,则此参数确定通配符表达式是否匹配隐藏的数据流则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔列表的值,如 `open,hidden`。有效的值有: 40 | 41 | 1. `all` 42 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 43 | 2. `open` 44 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 45 | 3. `closed` 46 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 47 | 4. `hidden` 48 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 49 | 5. `none` 50 | 不接受通配符表达式。 51 | 52 | 默认为 `open`。 53 | 54 | - `include_type_name` 55 | [~~7.0.0~~开始不推荐] (可选,布尔值)如果为 `true`,映射体中需要映射类型。 56 | 57 | - `ignore_unavailable` 58 | (可选,布尔值)如果为 `true`,请求不存在的索引将返回错误。默认为 `false`。 59 | 60 | - `local` 61 | (可选,布尔值)如果为 `true`,请求只从本地节点获取信息。默认为 `false`,意味着信息从主节点获取。 62 | 63 | - `master_timeout` 64 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 65 | 66 | ## 示例 67 | 68 | ### 多个数据流和索引 69 | 70 | 获取映射 API 可以一次请求获取多个数据流或索引。此 API 通常按以下语法使用:`host:port//_mapping`,`` 可接受逗号分隔的名字列表。为了获取集群中所有数据流和索引,`` 使用 `_all` 或 `*`,或者忽略参数 ``。以下为一些示例: 71 | 72 | ```bash 73 | GET /my-index-000001,my-index-000002/_mapping 74 | ``` 75 | 76 | 如果你想获取集群中所有索引的映射,以下示例都是等价的: 77 | 78 | ```bash 79 | GET /*/_mapping 80 | 81 | GET /_all/_mapping 82 | 83 | GET /_mapping 84 | ``` 85 | 86 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html) 87 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/import_dangling_index.md: -------------------------------------------------------------------------------- 1 | # 导入悬空索引 API 2 | 3 | 导入悬空索引。 4 | 5 | ## 请求 6 | 7 | ```bash 8 | POST /_dangling/?accept_data_loss=true 9 | ``` 10 | 11 | ## 前置条件 12 | 13 | - 如果 Elasticsearch 安全特性启用,你必须有 `manage` [集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)来使用此 API。 14 | 15 | ## 描述 16 | 17 | 如果 Elasticsearch 遇到当前集群状态中缺少的索引数据,则认为这些索引处于悬空状态。例如,如果在 Elasticsearch 节点脱机时删除多个 `cluster.index.tombstones.size` 索引,则可能会发生这种情况。 18 | 19 | 通过引用其 UUID 将单个索引导入集群。使用[列出悬空索引 API](/rest_apis/index_apis/list_dangling_indices) 定位索引的 UUID。 20 | 21 | ## 路径参数 22 | 23 | - `` 24 | 25 | (必需的,字符串)待导入索引的 UUID,你可以通过[列出悬空索引 API](/rest_apis/index_apis/list_dangling_indices) 找到它。 26 | 27 | ## 查询参数 28 | 29 | - `accept_data_loss` 30 | 31 | (必需的,布尔值)此字段必须设置为 `true` 才能导入悬空索引。由于 Elasticsearch 无法知道悬空索引数据来自何处,也无法确定哪些分片副本是新的,哪些是旧的,因此它无法保证导入的数据代表索引在集群中最后一次出现时的最新状态。 32 | 33 | - `master_timeout` 34 | 35 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 36 | 37 | - `timeout` 38 | 39 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 40 | 41 | ## 示例 42 | 43 | 以下示例展示如何导入一个悬空索引: 44 | 45 | ```bash 46 | POST /_dangling/zmM4e0JtBkeUjiHD-MihPQ?accept_data_loss=true 47 | ``` 48 | 49 | API 返回以下响应: 50 | 51 | ```bash 52 | { 53 | "acknowledged" : true 54 | } 55 | ``` 56 | 57 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/dangling-index-import.html) 58 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/index_apis.md: -------------------------------------------------------------------------------- 1 | # 索引 API 2 | 3 | 索引 API 用于管理单个索引、索引设置、别名、映射及索引模板。 4 | 5 | ## 索引管理 6 | 7 | - [创建索引](/rest_apis/index_apis/create_index) 8 | - [删除索引](/rest_apis/index_apis/delete_index) 9 | - [获取索引](/rest_apis/index_apis/get_index) 10 | - [索引存在](/rest_apis/index_apis/index_exists) 11 | - [关闭索引](/rest_apis/index_apis/close_index) 12 | - [开启索引](/rest_apis/index_apis/open_index) 13 | - [收缩索引](/rest_apis/index_apis/shrink_index) 14 | - [拆分索引](/rest_apis/index_apis/split_index) 15 | - [复制索引](/rest_apis/index_apis/clone_index) 16 | - [翻转](/rest_apis/index_apis/rollover_index) 17 | - [冻结索引](/rest_apis/index_apis/freeze_index) 18 | - [解冻索引](/rest_apis/index_apis/unfreeze_index) 19 | - [解析索引](/rest_apis/index_apis/resolve_index) 20 | 21 | ## 映射管理 22 | 23 | - [更新映射](/rest_apis/index_apis/update_mapping) 24 | - [获取映射](/rest_apis/index_apis/get_mapping) 25 | - [获取字段映射](/rest_apis/index_apis/get_field_mapping) 26 | - [类型存在](/rest_apis/index_apis/type_exists) 27 | 28 | ## 别名管理 29 | 30 | - [别名](/rest_apis/index_apis/aliases) 31 | - [创建或更新索引别名](/rest_apis/index_apis/create_or_update_index_alias) 32 | - [获取索引别名](/rest_apis/index_apis/get_index_alias) 33 | - [索引别名存在](/rest_apis/index_apis/index_alias_exists) 34 | - [删除索引别名](/rest_apis/index_apis/delete_index_alias) 35 | 36 | ## 索引设置 37 | 38 | - [更新索引设置](/rest_apis/index_apis/update_index_settings) 39 | - [获取索引设置](/rest_apis/index_apis/get_index_settings) 40 | - [分析](/rest_apis/index_apis/analyze) 41 | 42 | ## 索引模板 43 | 44 | 索引模板自动为新索引应用设置、映射以及别名。他们通常用于为时序数据配翻转索引,以确保每个新索引与前一个索引有相同的配置。关联到数据流的索引模板配置了它的和备份指示符。获取更多信息,参阅[索引模板](/index_templates/index_templates)。 45 | 46 | - [创建或更新索引模板](/rest_apis/index_apis/create_or_update_index_template) 47 | - [获取索引模板](/rest_apis/index_apis/get_index_template) 48 | - [删除索引模板](/rest_apis/index_apis/delete_index_template) 49 | - [创建或更新组件模板](/rest_apis/index_apis/create_or_update_component_template) 50 | - [获取组件模板](/rest_apis/index_apis/get_component_template) 51 | - [删除组件模板](/rest_apis/index_apis/delete_component_template) 52 | - [模拟索引](/rest_apis/index_apis/simulate_index) 53 | - [模拟模板](/rest_apis/index_apis/simulate_template) 54 | 55 | ## 监测 56 | 57 | - [索引统计](/rest_apis/index_apis/index_stats) 58 | - [索引段](/rest_apis/index_apis/index_segments) 59 | - [索引恢复](/rest_apis/index_apis/index_recovery) 60 | - [索引分片存储](/rest_apis/index_apis/index_shard_stores) 61 | 62 | ## 状态管理 63 | 64 | - [清除缓存](/rest_apis/index_apis/clear_cache) 65 | - [刷新](/rest_apis/index_apis/refresh) 66 | - [冲刷](/rest_apis/index_apis/flush) 67 | - [同步冲刷](/rest_apis/index_apis/synced_flush) 68 | - [强制合并](/rest_apis/index_apis/force_merge) 69 | 70 | ## 悬空索引 71 | 72 | - [列出悬空索引](/rest_apis/index_apis/list_dangling_indices) 73 | - [导入悬空索引](/rest_apis/index_apis/import_dangling_index) 74 | - [删除悬空索引](/rest_apis/index_apis/delete_dangling_index) 75 | 76 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices.html) 77 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/index_exists.md: -------------------------------------------------------------------------------- 1 | # 索引存在 API 2 | 3 | 检查索引是否存在。 4 | 5 | ```bash 6 | HEAD /my-index-000001 7 | ``` 8 | 9 | ## 请求 10 | 11 | `HEAD /` 12 | 13 | ## 前置条件 14 | 15 | - 如果 Elasticsearch 安全特性启用,你对目标索引必须有 `view_index_metadata` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 16 | 17 | ## 路径参数 18 | 19 | - `` 20 | 21 | (可选,字符串)用于限制请求的,逗号分隔的数据流、索引。也支持通配符表达式(*)。 22 | 23 | ## 查询参数 24 | 25 | - `allow_no_indices` 26 | 27 | (可选,布尔值)如果为 `false`,如果任何通配符表达式、索引别名或 `_all` 值只针对丢失或关闭的索引,则请求返回一个错误。即使请求以其他开放索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,但没有索引以 `bar` 开头,以 `foo*,bar*` 为目标的请求将返回错误。 28 | 29 | 默认为 `true`。 30 | 31 | - `expand_wildcards` 32 | 33 | (可选,字符串)通配符表达式能匹配的索引类型。如果请求目标为数据流,则此参数确定通配符表达式是否匹配隐藏的数据流则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔列表的值,如 `open,hidden`。有效的值有: 34 | 35 | 1. `all` 36 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 37 | 2. `open` 38 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 39 | 3. `closed` 40 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 41 | 4. `hidden` 42 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 43 | 5. `none` 44 | 不接受通配符表达式。 45 | 46 | - `flat_settings` 47 | 48 | (可选,布尔值)如果为 `true`,以平面格式返回设置。默认为 `false`。 49 | 50 | - `include_defaults` 51 | 52 | (可选,字符串)如果为 `true`,在响应中返回所有默认设置。默认为 `false`。 53 | 54 | - `ignore_unavailable` 55 | 56 | (可选,布尔值)如果为 `true`,请求不存在的索引将返回错误。默认为 `false`。 57 | 58 | - `local` 59 | 60 | (可选,布尔值)如果为 `true`,请求只从本地节点检索信息。默认为 `false`,意味着从主节点检索信息。 61 | 62 | ## 响应码 63 | 64 | - `200` 65 | 66 | 表明所有指定的索引或索引别名存在。 67 | 68 | - `404` 69 | 70 | 表明一个至多个索引或索引别名**不**存在。 71 | 72 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-exists.html) 73 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/index_shard_stores.md: -------------------------------------------------------------------------------- 1 | # 索引分片存储 API 2 | 3 | 返回在一个或多个索引中关于副本分片的存储信息。对于数据流,API 返回流的备份索引的存储信息。 4 | 5 | ```bash 6 | GET /my-index-000001/_shard_stores 7 | ``` 8 | 9 | ## 请求 10 | 11 | `GET //_shard_stores` 12 | 13 | `GET /_shard_stores` 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你使用此 API 必须有 `monitor` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 18 | 19 | ## 描述 20 | 21 | 索引分片存储 API 返回以下信息: 22 | 23 | - 每个副本分片存在哪个节点 24 | - 每个副本分片分配的 ID 25 | - 每个副本分片唯一 ID 26 | - 打开分片索引时遇到的任何错误或早期故障导致的任何错误 27 | 28 | 默认情况,API 只返回未分配或有一到多个未分配副本分片的主分片存储信息。 29 | 30 | ## 路径参数 31 | 32 | - `` 33 | 34 | (可选,字符串)限制请求的逗号分隔的数据流、索引和别名的列表。支持通配符(*)。要以所有数据流和索引为目标,忽略此参数或使用 `*` 或 `_all`。 35 | 36 | ## 查询参数 37 | 38 | - `allow_no_indices` 39 | 40 | (可选,布尔值)如果为 `false`,任何通配符、[索引别名](/rest_apis/index_apis/bulk_index_alias)或 `_all` 值只针对丢失或关闭的索引,请求将返回一个错误。即使请求以其他开启索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,而没有索引以 `bar` 开头,则以 `foo*,bar*` 为目标的请求将返回错误。 41 | 42 | - `expand_wildcards` 43 | 44 | (可选,字符串)通配符表达式可以匹配的索引类型。如果请求可以数据流为目标,则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 `open,hidden`。有效的值有: 45 | 46 | 1. `all` 47 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 48 | 2. `open` 49 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 50 | 3. `closed` 51 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 52 | 4. `hidden` 53 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 54 | 5. `none` 55 | 不接受通配符表达式。 56 | 57 | 默认为 `open`。 58 | 59 | - `ignore_unavailable` 60 | 61 | (可选,布尔值)如果为 `true`,丢失的或关闭的索引不包含在响应中。默认为 `false`。 62 | 63 | - `status` 64 | 65 | (可选,字符串)用于限制请求的,逗号分隔的分片健康状态。 66 | 67 | 有效值包括: 68 | 69 | - `green` 70 | 71 | 主分片和所有副本分片都已分配。 72 | 73 | - `yellow` 74 | 75 | 一个或多个副本分片未分配。 76 | 77 | - `red` 78 | 79 | 主分片未分配。 80 | 81 | - `all` 82 | 83 | 返回所有分片,忽略健康状态。 84 | 85 | 默认为 `yellow,red`。 86 | 87 | ## 示例 88 | 89 | ### 获取特定数据流或索引的分片存储信息 90 | 91 | ```bash 92 | GET /test/_shard_stores 93 | ``` 94 | 95 | ### 获取多个数据流和索引的分片存储信息 96 | 97 | ```bash 98 | GET /test1,test2/_shard_stores 99 | ``` 100 | 101 | ### 获取所有数据流和索引的分片存储信息 102 | 103 | ```bash 104 | GET /_shard_stores 105 | ``` 106 | 107 | ### 基于集群运行状况获取分片存储信息 108 | 109 | 你可以使用查询参数 `status` 来限制基于分片健康的返回信息。 110 | 111 | 以下的请求只返回已分配的主分片和副本分片信息。 112 | 113 | ```bash 114 | GET /_shard_stores?status=green 115 | ``` 116 | 117 | API 返回以下响应: 118 | 119 | ```bash 120 | { 121 | "indices": { 122 | "my-index-00001": { 123 | "shards": { 124 | "0": { 125 | "stores": [ 126 | { 127 | "sPa3OgxLSYGvQ4oPs-Tajw": { 128 | "name": "node_t0", 129 | "ephemeral_id": "9NlXRFGCT1m8tkvYCMK-8A", 130 | "transport_address": "local[1]", 131 | "attributes": {}, 132 | "roles": [...] 133 | }, 134 | "allocation_id": "2iNySv_OQVePRX-yaRH_lQ", 135 | "allocation": "primary|replica|unused", 136 | "store_exception": ... 137 | } 138 | ] 139 | } 140 | } 141 | } 142 | } 143 | } 144 | ``` 145 | 146 | 1. `"0": {` : 密钥是存储信息的对应分片 id 147 | 2. `"stores": [`:分片所有副本的存储信息列表 148 | 3. `"sPa3OgxLSYGvQ4oPs-Tajw": {`: 托管存储副本的节点信息,密钥是唯一的节点 id 149 | 4. `"allocation_id": "2iNySv_OQVePRX-yaRH_lQ",`:存储副本的分配 id 150 | 5. `"allocation": "primary|replica|unused"`: 存储副本的状态,无论它是否用作主副本、副本还是根本未使用 151 | 6. `"store_exception": ...`:打开分片索引或早期引擎故障时遇到的任何异常 152 | 153 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-shards-stores.html) 154 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/list_dangling_indices.md: -------------------------------------------------------------------------------- 1 | # 列出悬空索引 API 2 | 3 | 列出悬空索引。 4 | 5 | ## 请求 6 | 7 | ```bash 8 | GET /_dangling 9 | ``` 10 | 11 | ## 前置条件 12 | 13 | - 如果 Elasticsearch 安全特性启用,你必须有 `manage` [集群权限](/secure_the_elastic_statck/user_authorization/security_privileges#集群权限)来使用此 API。 14 | 15 | ## 描述 16 | 17 | 如果 Elasticsearch 遇到当前集群状态中缺少的索引数据,则认为这些索引处于悬空状态。例如,如果在 Elasticsearch 节点脱机时删除多个 `cluster.index.tombstones.size` 索引,则可能会发生这种情况。 18 | 19 | 使用此 API 列出悬空索引,你就可以[导入](/rest_apis/index_apis/import_dangling_index)或[删除](/rest_apis/index_apis/delete_dangling_index)它们。 20 | 21 | ## 示例 22 | 23 | API 返回以下响应: 24 | 25 | ```bash 26 | { 27 | "dangling_indices": [ 28 | { 29 | "index_name": "my-index-000001", 30 | "index_uuid": "zmM4e0JtBkeUjiHD-MihPQ", 31 | "creation_date_millis": 1589414451372, 32 | "node_ids": [ 33 | "pL47UN3dAb2d5RCWP6lQ3e" 34 | ] 35 | } 36 | ] 37 | } 38 | ``` 39 | 40 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/dangling-indices-list.html) 41 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/open_index.md: -------------------------------------------------------------------------------- 1 | # 开启索引 API 2 | 3 | 开启关闭的索引。对数据流而言,API 打开所有关闭的备份索引。 4 | 5 | ```bash 6 | POST /my-index-000001/_open 7 | ``` 8 | 9 | ## 请求 10 | 11 | `POST //_open` 12 | 13 | ## 前置条件 14 | 15 | - 如果 Elasticsearch 安全特性启用,你对目标索引必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 16 | 17 | ## 描述 18 | 19 | 你可以使用开启索引 API 重新打开关闭的索引。如果请求目标是数据流,请求重新打开任何数据流关闭的后备索引。 20 | 21 | 关闭的索引被阻止进行读/写操作,也不允许开启的索引允许的所有操作。在关闭的索引中无法索引文档或搜索文档。这允许关闭的索引不必维护索引或搜索文档的内部数据结构,以减少集群的开销。 22 | 23 | 当打开或关闭索引时,主节点负责重新启动索引分片以反映索引的新状态。分片将经过正常的恢复过程。打开的/关闭的索引数据由集群自动复制,以确保始终安全地保留足够的分片副本。 24 | 25 | 你可以打开和关闭多个索引。如果请求显示引用缺失的索引,会抛出错误。这个行为可以通用 `ignore_unavailable=true` 参数禁用。 26 | 27 | 所有索引可以通过 `_all` 作为索引名字或指定标识所有索引模式(如 `*`)来一次打开或关闭。 28 | 29 | 在配置文件中通过设置 `action.destructive_requires_name` 标识为 `true`,可以禁用通过通配符或 `_all` 来定义所有索引。这个设置也可以通过集群更新设置 API 来修改。 30 | 31 | 关闭的索引会消耗显著数量的硬盘空间,这在托管环境中可能会造成问题。通过集群设置 API 将 `cluster.indices.close.enable` 设置为 `false`,可以禁用关闭索引。默认值为 `true`。 32 | 33 | 在7.12.0及更早版本中,无法关闭数据流上的当前写入索引。为了关闭当前写索引,数据流必须先被[翻转](/data_streams/data_streams#翻转)以便创建新的写入索引,这样之前的写入索引能被关闭。此限制从 7.12.1 不再适用。 34 | 35 | ## 等待活动分片 36 | 37 | 因为打开或关闭索引会分配其分片,在创建索引时,[`wait_for_active_shards`](/index_apis/create_index#等待活动分片) 设置也适用于 `_open` 和 `_close` 索引操作。 38 | 39 | ## 路径参数 40 | 41 | - `` 42 | 43 | (可选,字符串)用于限制请求的,逗号分隔的数据流、索引。也支持通配符表达式(*)。 44 | 45 | 若要以集群中的所有数据流和索引为目标,省略此参数或使用 `_all` 或 `*`。 46 | 47 | 使用 `_all` 或 `*` 关闭所有索引。修改 `action.destructive_requires_name` 集群设置为 `true`,可以禁用通过 `_all` 或 `*` 关闭索引。你可以在文件 `elasticsearch.yml` 中 或通过 [集群更新设置](/rest_apis/cluster_apis/cluster_update_settings.html) API 来更新这个设置。 48 | 49 | ## 查询参数 50 | 51 | - `allow_no_indices` 52 | 53 | (可选,布尔值)如果为 `false`,如果任何通配符表达式、索引别名或 `_all` 值只针对丢失或关闭的索引,则请求返回一个错误。即使请求以其他开放索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,但没有索引以 `bar` 开头,以 `foo*,bar*` 为目标的请求将返回错误。 54 | 55 | 默认为 `true`。 56 | 57 | - `expand_wildcards` 58 | 59 | (可选,字符串)通配符表达式能匹配的索引类型。如果请求目标为数据流,则此参数确定通配符表达式是否匹配隐藏的数据流则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔列表的值,如 `open,hidden`。有效的值有: 60 | 61 | 1. `all` 62 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 63 | 2. `open` 64 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 65 | 3. `closed` 66 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 67 | 4. `hidden` 68 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 69 | 5. `none` 70 | 不接受通配符表达式。 71 | 72 | 默认为 `open`。 73 | 74 | - `ignore_unavailable` 75 | (可选,布尔值)如果为 `true`,丢失的或关闭的索引不包含在响应中。默认为 `false`。 76 | 77 | - `wait_for_active_shards` 78 | (可选,字符串)在操作执行之前必须活动的分片复制数量。设置为 `all` 或任何正整数,最大值为索引分片总数(`number_of_replicas+1`)。值 `index-setting` 指依据索引设置 `index.write.wait_for_active_shards` 等待。默认:`0`,意味着不等待任何分片准备。 79 | 80 | 参阅[活动分片](/rest_apis/document_apis/docs_index#活动分片)。 81 | 82 | - `master_timeout` 83 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 84 | 85 | - `timeout` 86 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 87 | 88 | ## 示例 89 | 90 | 以下请求重新打开名为 `my-index-000001` 的关闭的索引。 91 | 92 | ```bash 93 | POST /my-index-000001/_open 94 | ``` 95 | 96 | API 返回以下响应: 97 | 98 | ```json 99 | { 100 | "acknowledged" : true, 101 | "shards_acknowledged" : true 102 | } 103 | ``` 104 | 105 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html) 106 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/refresh.md: -------------------------------------------------------------------------------- 1 | # 刷新 API 2 | 3 | 刷新使最近对一个或多个索引执行的操作可用于搜索。对于数据流,API 在流的备份索引上执行刷新操作。有关刷新操作的更多信息,参阅[接近实时的搜索](/search_your_data/near_real-time_search)。 4 | 5 | ```bash 6 | POST /my-index-000001/_refresh 7 | ``` 8 | 9 | ## 请求 10 | 11 | `POST /_refresh` 12 | 13 | `GET /_refresh` 14 | 15 | `POST /_refresh` 16 | 17 | `GET /_refresh` 18 | 19 | ## 前置条件 20 | 21 | - 如果 Elasticsearch 安全特性启用,你对目标数据流、索引或别名必须有 `maintenance` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限) 22 | 23 | ## 描述 24 | 25 | 使用刷新 API 显式地使自上次刷新以来对一个或多个索引执行的所有操作可用于搜索。如果请求目标是数据流,它将刷新数据流的备份索引。 26 | 27 | 默认情况下,Elasticsearch 每秒定期刷新索引,但仅针对在过去 30 秒内收到一个或多个搜索请求的索引。你可以使用设置 [index.refresh_interval](/index_modules) 修改默认间隔。 28 | 29 | 刷新请求是异步的,不会返回响应直到刷新操作完成。 30 | 31 | :::caution 警告 32 | 刷新是资源密集型的。为了确保良好的集群性能,我们建议尽可能等待 Elasticsearch 的定期刷新,而不是执行显式刷新。 33 | 如果应用程序工作流为文档编制索引,然后运行搜索以检索索引文档,则建议使用[索引 API](/rest_apis) 的 `refresh=wait_for` 参数选项。此选项确保索引操作在运行搜索之前等待定期刷新。 34 | ::: 35 | 36 | ## 路径参数 37 | 38 | - `` 39 | 40 | (可选,字符串)限制请求的逗号分隔的数据流、索引和别名的列表。支持通配符(*)。要以所有数据流和索引为目标,忽略此参数或使用 `*` 或 `_all`。 41 | 42 | ## 查询参数 43 | 44 | - `allow_no_indices` 45 | 46 | (可选,布尔值)如果为 `false`,任何通配符、[索引别名](/rest_apis/index_apis/bulk_index_alias)或 `_all` 值只针对丢失或关闭的索引,请求将返回一个错误。即使请求以其他开启索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,而没有索引以 `bar` 开头,则以 `foo*,bar*` 为目标的请求将返回错误。 47 | 48 | 默认为 `true`。 49 | 50 | - `expand_wildcards` 51 | 52 | (可选,字符串)通配符表达式可以匹配的索引类型。如果请求可以数据流为目标,则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 `open,hidden`。有效的值有: 53 | 54 | 1. `all` 55 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 56 | 2. `open` 57 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 58 | 3. `closed` 59 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 60 | 4. `hidden` 61 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 62 | 5. `none` 63 | 不接受通配符表达式。 64 | 65 | 默认为 `open`。 66 | 67 | - `ignore_unavailable` 68 | 69 | (可选,布尔值)如果为 `true`,丢失或关闭的索引不包含在响应中。 70 | 71 | 默认为 `false`。 72 | 73 | ## 示例 74 | 75 | ### 刷新多个数据流和索引 76 | 77 | ```bash 78 | POST /my-index-000001,my-index-000002/_refresh 79 | ``` 80 | 81 | ### 刷新集群中所有数据流和索引 82 | 83 | ```bash 84 | POST /_refresh 85 | ``` 86 | 87 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html) 88 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/resolve_index.md: -------------------------------------------------------------------------------- 1 | # 解析索引 API 2 | 3 | 解析索引、别名和数据流的指定名称和(或)索引模式。 4 | 5 | 支持多种模式以及远程集群。 6 | 7 | ```bash 8 | GET /_resolve/index/my-index-* 9 | ``` 10 | 11 | ## 请求 12 | 13 | `GET /_resolve/index/` 14 | 15 | ## 前置条件 16 | 17 | - 如果 Elasticsearch 安全特性启用,你对目标数据流、索引或索引别名必须有 `view_index_metadata` 或 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 18 | 19 | ## 路径参数 20 | 21 | `` 22 | 23 | (必需,字符串)逗号分隔的待解析的索引、别名及数据流的名字或索引模式。在[远程集群](/set_up_elasticsearch/remote_clusters)上的资源可以通过语法 `:` 指定。 24 | 25 | ## 查询参数 26 | 27 | - `expand_wildcards` 28 | (可选,字符串)通配符表达式可以匹配的索引类型。如果请求可以数据流为目标,则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔的值,如 `open,hidden`。有效的值有: 29 | 30 | 1. `all` 31 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 32 | 2. `open` 33 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 34 | 3. `closed` 35 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 36 | 4. `hidden` 37 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 38 | 5. `none` 39 | 不接受通配符表达式。 40 | 41 | 默认为 `open`。 42 | 43 | ## 示例 44 | 45 | ```bash 46 | GET /_resolve/index/f*,remoteCluster1:bar*?expand_wildcards=all 47 | ``` 48 | 49 | API 返回以下响应: 50 | 51 | ```bash 52 | { 53 | "indices": [ 54 | { 55 | "name": "foo_closed", 56 | "attributes": [ 57 | "closed" 58 | ] 59 | }, 60 | { 61 | "name": "freeze-index", 62 | "aliases": [ 63 | "f-alias" 64 | ], 65 | "attributes": [ 66 | "frozen", 67 | "open" 68 | ] 69 | }, 70 | { 71 | "name": "remoteCluster1:bar-01", 72 | "attributes": [ 73 | "open" 74 | ] 75 | } 76 | ], 77 | "aliases": [ 78 | { 79 | "name": "f-alias", 80 | "indices": [ 81 | "freeze-index", 82 | "my-index-000001" 83 | ] 84 | } 85 | ], 86 | "data_streams": [ 87 | { 88 | "name": "foo", 89 | "backing_indices": [ 90 | ".ds-foo-2099.03.07-000001" 91 | ], 92 | "timestamp_field": "@timestamp" 93 | } 94 | ] 95 | } 96 | ``` 97 | 98 | - `indices` 与提供的名字或表达式匹配的所有索引 99 | - `aliases` 与提供的名字或表达式匹配的所有别名 100 | - `data_streams` 与提供的名字或表达式匹配的所有数据流 101 | 102 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-resolve-index-api.html) 103 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/type_exists.md: -------------------------------------------------------------------------------- 1 | # 类型存在 API 2 | 3 | :::caution 警告 4 | **7.0.0 废弃** 类型不推荐,且后续会被移除。参阅[移除映射类型](/mapping/removal_of_mapping_types)。 5 | ::: 6 | 7 | 检查[映射类型](/mapping/metadata_fields/_type_field)是否存在。 8 | 9 | ```bash 10 | HEAD my-index-000001/_mapping/message 11 | ``` 12 | 13 | ## 请求 14 | 15 | `HEAD //_mapping/` 16 | 17 | ## 路径参数 18 | 19 | `` 20 | (可选,字符串)用于限制请求的,逗号分隔的索引名字列表或通配符。 21 | 22 | `` 23 | (可选,字符串)用于限制请求的,逗号分隔类型列表或通配符。 24 | 25 | ## 响应码 26 | 27 | `200` 28 | 表明所有指定映射类型存在。 29 | 30 | `404` 31 | 表明一个或多个指定映射类型不存在。 32 | 33 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-types-exists.html) 34 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/unfreeze_index.md: -------------------------------------------------------------------------------- 1 | # 解冻索引 API [`X-Pack`] 2 | 3 | 解冻一个索引。 4 | 5 | ## 请求 6 | 7 | `POST //_unfreeze` 8 | 9 | ## 前置条件 10 | 11 | - 如果 Elasticsearch 安全特性启用,你对目标索引或索引别名必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 12 | 13 | ## 描述 14 | 15 | 当一个冻结索引被解冻,索引会通过正常的恢复过程再次变为可写。参阅[已冻结索引](/frozen_indices/frozen_indices)和[冻结索引](/rest_apis/index_apis/freeze_index)。 16 | 17 | :::caution 警告 18 | 冻结一个索引会在同一个 API 调用中关闭这个索引并且重新打开它。这将导致在短时间内主分片不被分配,直到再次分配主分片前集群会变为红色(red)。这个限制在未来可能被移除。 19 | ::: 20 | 21 | ## 路径参数 22 | 23 | `` 24 | 25 | (必需,字符串)标识索引。 26 | 27 | ## 示例 28 | 29 | 以下的示例冻结和解冻一个索引。 30 | 31 | ```bash 32 | POST /my-index-000001/_freeze 33 | POST /my-index-000001/_unfreeze 34 | ``` 35 | 36 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/unfreeze-index-api.html) 37 | -------------------------------------------------------------------------------- /docs/rest_apis/index_apis/update_index_settings.md: -------------------------------------------------------------------------------- 1 | # 更新索引设置 2 | 3 | 实时修改[动态索引设置](/index_modules)。 4 | 5 | 对数据流,索引设置更改默认应用于所有备份索引。 6 | 7 | ```bash 8 | PUT /my-index-000001/_settings 9 | { 10 | "index" : { 11 | "number_of_replicas" : 2 12 | } 13 | } 14 | ``` 15 | 16 | ## 请求 17 | 18 | `PUT //_settings` 19 | 20 | ## 前置条件 21 | 22 | - 如果 Elasticsearch 安全特性启用,你对目标数据流、索引或别名必须有 `manage` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 23 | 24 | ## 路径参数 25 | 26 | - `` 27 | 28 | (可选,字符串)限制请求的逗号分隔的数据流、索引和别名的列表。支持通配符(*)。要以所有数据流和索引为目标,忽略此参数或使用 `*` 或 `_all`。 29 | 30 | ## 查询参数 31 | 32 | - `allow_no_indices` 33 | 34 | (可选,布尔值)如果为 `false`,如果任何通配符表达式、索引别名或 `_all` 值只针对丢失或关闭的索引,则请求返回一个错误。即使请求以其他开放索引为目标,此行为也适用。例如,如果一个索引以 `foo` 开头,但没有索引以 `bar` 开头,以 `foo*,bar*` 为目标的请求将返回错误。 35 | 36 | 默认为 `true`。 37 | 38 | - `expand_wildcards` 39 | 40 | (可选,字符串)通配符表达式能匹配的索引类型。如果请求目标为数据流,则此参数确定通配符表达式是否匹配隐藏的数据流则此参数确定通配符表达式是否匹配隐藏的数据流。支持逗号分隔列表的值,如 `open,hidden`。有效的值有: 41 | 42 | 1. `all` 43 | 匹配任何数据流或索引,包括 [hidden](/rest_apis/api_convention/multi_target_syntax#隐藏数据流和索引)(隐藏的)。 44 | 2. `open` 45 | 匹配 open(开启)、非隐藏的索引。也匹配任何非隐藏的数据流。 46 | 3. `closed` 47 | 匹配 closed(关闭)、非隐藏的索引。也匹配任何非隐藏的数据流。数据流不能关闭。 48 | 4. `hidden` 49 | 匹配隐藏数据流和隐藏索引。必须与 `open`、`closed` 或一起使用。 50 | 5. `none` 51 | 不接受通配符表达式。 52 | 53 | 默认为 `open`。 54 | 55 | - `flat_settings` 56 | 57 | (可选,布尔值)如果为 `true`,以平面格式返回设置。默认为 `false`。 58 | 59 | - `ignore_unavailable` 60 | 61 | (可选,布尔值)如果为 `true`,丢失的或关闭的索引不包含在响应中。默认为 `false`。 62 | 63 | - `preserve_existing` 64 | 65 | (可选,布尔值)如果为 `true`,已有的索引设置保持不变。默认为 `false`。 66 | 67 | - `master_timeout` 68 | 69 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待连接到主节点的时间。如果在超时过期前没有收到响应,则请求失败并返回错误。默认为 `30s`。 70 | 71 | - `timeout` 72 | 73 | (可选,[时间单位](/rest_apis/api_convention/common_options#时间单位))等待响应的时间。如果在超时过期之前没有收到响应,则请求失败并返回错误。默认为 `30s`。 74 | 75 | ## 请求体 76 | 77 | - `settings` 78 | 79 | (可选,[索引设置对象](/index_modules#索引设置))索引配置选项。参阅[索引设置](/index_modules#索引设置)。 80 | 81 | ## 示例 82 | 83 | ### 重置索引设置 84 | 85 | 要将设置还原为默认值,请使用 `null`。示例: 86 | 87 | ```bash 88 | PUT /my-index-000001/_settings 89 | { 90 | "index" : { 91 | "refresh_interval" : null 92 | } 93 | } 94 | ``` 95 | 96 | 在[索引模块](/index_modules)中可以找到每个索引设置的列表,这些设置可以在活动索引上动态更新。 97 | 98 | 要防止更新已有设置,可以将 `preserve_existing` 请求参数设置为 `true`。 99 | 100 | ### 批量索引使用 101 | 102 | 例如,可以使用更新索引 API 动态地更改索引,使其在大容量索引中性能更好,然后将其移动到更实时的索引状态。在开始批量索引之前,请使用: 103 | 104 | ```bash 105 | PUT /my-index-000001/_settings 106 | { 107 | "index" : { 108 | "refresh_interval" : "-1" 109 | } 110 | } 111 | ``` 112 | 113 | (另一个优化选项是在没有任何副本的情况下启动索引,然后才添加副本,但这实际上取决于用例)。 114 | 115 | 然后,一旦完成批量索引,就可以更新设置(例如,返回到默认值): 116 | 117 | ```bash 118 | PUT /my-index-000001/_settings 119 | { 120 | "index" : { 121 | "refresh_interval" : "1s" 122 | } 123 | } 124 | ``` 125 | 126 | 并且,应调用强制合并: 127 | 128 | ```bash 129 | POST /my-index-000001/_forcemerge?max_num_segments=5 130 | ``` 131 | 132 | ### 更新索引分析 133 | 134 | 只能在关闭的索引上定义新的分析器。 135 | 136 | 要添加分析器,必须关闭索引,定义分析器,然后重新打开索引。 137 | 138 | :::note 提示 139 | 你不能关闭数据流的写索引。 140 | ::: 141 | 142 | 要为数据流的写入索引和将来的备份索引更新分析器,请在[流使用的索引模板](data_streams/set_up_a_data_stream#第三步_创建一个索引模板)中更新分析器。然后[翻转数据流](/data_streams/use_a_data_stream#手动翻转数据流),将新的分析器应用于流的写索引和未来的备份索引。这会影响滚动更新后添加到流中的搜索和任何新数据。但是,它不会影响数据流的支持索引或其现有数据。 143 | 要更改现有备份索引的分析器,必须创建新的数据流并将数据重新索引到其中。参阅[使用重索引更改映射或设置](/data_streams/change_mappings_and_settings_for_a_data_stream#使用重索引更改映射或设置)。 144 | 145 | 例如,以下命令将为索引 `my-index-000001` 添加内容分析器: 146 | 147 | ```bash 148 | POST /my-index-000001/_close?wait_for_active_shards=0 149 | 150 | PUT /my-index-000001/_settings 151 | { 152 | "analysis" : { 153 | "analyzer":{ 154 | "content":{ 155 | "type":"custom", 156 | "tokenizer":"whitespace" 157 | } 158 | } 159 | } 160 | } 161 | 162 | POST /my-index-000001/_open 163 | ``` 164 | 165 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html) 166 | -------------------------------------------------------------------------------- /docs/rest_apis/rest_apis.md: -------------------------------------------------------------------------------- 1 | # REST API 2 | 3 | Elasticsearch 暴露的 REST API,提供给 UI 组件使用,也可以直接被调用来配置及访问 Elasticsearch 特性。 4 | 5 | :::note 提示 6 | 我们致力于在本节中包含更多的 Elasticsearch APIs。一些内容可能可能还没被包含。 7 | ::: 8 | 9 | - [API 约定](/rest_apis/api_conventions/api_conventions) 10 | - [自动缩放 API](/rest_apis/autoscaling_apis) 11 | - [cat API](/rest_apis/cat_apis/cat_apis) 12 | - [集群 API](/rest_apis/cluster_apis/cluster_apis) 13 | - [跨集群复制 API](/rest_apis/cross_cluster_replication_apis/cross_cluster_replication_apis) 14 | - [数据流 API](/rest_apis/data_stream_apis/data_stream_apis) 15 | - [文档 API](/rest_apis/document_apis) 16 | - [Enrich API](/rest_apis/enrich_apis/enrich_apis) 17 | - [图形浏览 API](/rest_apis/graph_explore_api/graph_explore_api) 18 | - [索引 API](/rest_apis/index_apis) 19 | - [索引生命周期管理 API](/rest_apis/index_lifecycle_management_apis/index_lifecycle_management_apis) 20 | - [摄入 API](/rest_apis/ingest_apis/ingest_apis) 21 | - [信息 API](/rest_apis/info_api) 22 | - [授权 API](/rest_apis/licensing_apis/licensing_apis) 23 | - [机器学习异常检测 API](/rest_apis/machine_learning_apis/machine_learning_apis) 24 | - [机器学习数据帧分析 API](/rest_apis/machine_learning_data_frame_analytics_apis/machine_learning_data_frame_analytics_apis) 25 | - [迁移 API](/rest_apis/migration_apis/migration_apis) 26 | - [重新加载搜索分析器 API](/rest_apis/reload_search_analyzers_api/reload_search_analyzers_api) 27 | - [仓库计量 API](/rest_apis/repositories_metering_apis/repositories_metering_apis) 28 | - [汇总 API](/rest_apis/rollup_apis/rollup_apis) 29 | - [搜索 API](/rest_apis/search_apis) 30 | - [可搜索快照 API](/rest_apis/searchable_snapshots_apis/searchable_snapshots_apis) 31 | - [安全 API](/rest_apis/security_apis/security_apis) 32 | - [快照和还原 API](/rest_apis/snapshot_and_restore_apis/snapshot_and_restore_apis) 33 | - [快照生命周期管理 API](/rest_apis/snapshot_lifecycle_management_apis/snapshot_lifecycle_management_apis) 34 | - [转换 API](/rest_apis/transform_apis/transform_apis) 35 | - [使用 API](/rest_apis/usage_api) 36 | - [观察者 API](/rest_apis/watcher_apis/watcher_apis) 37 | -------------------------------------------------------------------------------- /docs/rest_apis/search_apis/clear_scroll.md: -------------------------------------------------------------------------------- 1 | # 清除滚动 API 2 | 3 | 清除[滚动搜索](/rest_apis/search_apis/scroll)的搜索上下文和结果。 4 | 5 | ```bash 6 | DELETE /_search/scroll 7 | { 8 | "scroll_id" : "DXF1ZXJ5QW5kRmV0Y2gBAAAAAAAAAD4WYm9laVYtZndUQlNsdDcwakFMNjU1QQ==" 9 | } 10 | ``` 11 | 12 | ## 请求 13 | 14 | `DELETE /_search/scroll/` [~~7.0.0~~] 15 | 16 | `DELETE /_search/scroll` 17 | 18 | ## 路径参数 19 | 20 | - `` 21 | [~~7.0.0~~](可选,字符串)搜索的滚动 ID。 22 | 23 | :::caution 警告 24 | 滚动 ID 可能很长。我们建议仅使用 [`scroll_id` 请求体参数](/rest_apis/search_apis/scroll)指定滚动 ID。 25 | ::: 26 | 27 | ## 查询参数 28 | 29 | - `scroll_id` 30 | [~~7.0.0~~](可选,字符串)搜索的滚动 ID。 31 | 32 | :::caution 警告 33 | 滚动 ID 可能很长。我们建议仅使用 [`scroll_id` 请求体参数](/rest_apis/search_apis/scroll)指定滚动 ID。 34 | ::: 35 | 36 | ## 请求体 37 | 38 | - `scroll_id` 39 | 40 | (必需,字符串)搜索的滚动 ID。 41 | 42 | ## 响应体 43 | 44 | - `succeeded` 45 | 46 | (布尔值)如果为 `true`,请求成功。这并不表示是否清除了任何滚动搜索请求。 47 | 48 | - `num_freed` 49 | 50 | (整数)已清除的滚动搜索请求数。 51 | 52 | > [原文链接](https://www.elastic.co/guide/en/elasticsearch/reference/current/clear-scroll-api.html) 53 | -------------------------------------------------------------------------------- /docs/rest_apis/search_apis/render_search_template.md: -------------------------------------------------------------------------------- 1 | # 渲染搜索模板 API 2 | 3 | 将[搜索模板](/rest_apis/search_apis/search_template)呈现为[搜索请求体](/rest_apis/search_apis/search)。 4 | 5 | ```bash 6 | POST _render/template 7 | { 8 | "id": "my-search-template", 9 | "params": { 10 | "query_string": "hello world", 11 | "from": 20, 12 | "size": 10 13 | } 14 | } 15 | ``` 16 | 17 | ## 请求 18 | 19 | `GET _render/template` 20 | 21 | `GET _render/template/` 22 | 23 | `POST _render/template` 24 | 25 | `POST _render/template/` 26 | 27 | ## 前置条件 28 | 29 | - 如果 Elasticsearch 安全特性启用,你对至少一个索引模型必须有 `read` [索引权限](/secure_the_elastic_statck/user_authorization/security_privileges#索引权限)。 30 | 31 | ## 路径参数 32 | 33 | - `` 34 | (必需,字符串)待渲染的搜索模板 ID。如果 `source` 未指定,此参数或请求体中的 `id` 将是必需的。 35 | 36 | ## 请求体 37 | 38 | - `id` 39 | (必需,字符串)待渲染的搜索模板的 ID。如果 `source` 未指定,则此参数或请求路径参数 `` 是必需的。如果同时指定此参数和 `