要在 Elasticsearch 中创建索引,您可以使用以下 API 请求:

PUT /<索引名称>
{
  "settings": {
    "number_of_shards": <主分片数量>,
    "number_of_replicas": <副本分片数量>
  },
  "mappings": {
    "properties": {
      "<字段名称>": {
        "type": "<字段类型>"
      },
      ...
    }
  }
}

其中 <索引名称> 是您想要创建的索引的名称,<主分片数量> 是主分片数量,<副本分片数量> 是副本分片数量。<字段名称> 是您想要在索引中定义的字段的名称,<字段类型> 是字段的类型。

以下是一个示例请求:

PUT /my_index
{
  "settings": {
    "number_of_shards": 3,
    "number_of_replicas": 2
  },
  "mappings": {
    "properties": {
      "title": {
        "type": "text"
      },
      "description": {
        "type": "text"
      },
      "price": {
        "type": "float"
      },
      "category": {
        "type": "keyword"
      }
    }
  }
}

此请求将创建一个名为 my_index 的索引,具有 3 个主分片和 2 个副本分片。它还定义了几个字段,包括 titledescriptionpricecategory

请根据您的需求修改以上请求,并将其发送到 Elasticsearch 的 REST API 来创建索引

es 创建索引

原文地址: https://www.cveoy.top/t/topic/iugz 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录