1.首先,确认你的 elasticsearch 平台正在运行。
2.打开一个命令行窗口,使用 curl 命令发送以下请求:
创建索引
curl -X PUT "localhost:9200/test-index"
curl -X PUT -u elastic:密码 "localhost:9200/test-index" #es加密方式
以上命令会创建一个名为 "test-index" 的新索引。你可以用自己的名称来替换 "test-index"。
3.为索引设置映射。映射是定义索引的字段和类型的重要步骤。以下是设置映射的示例命令:
curl -X PUT "localhost:9200/my-index/_mapping" -H 'Content-Type: application/json' -d'
{
"properties": {
"title": { "type": "text" },
"content": { "type": "text" }
}
}
'
以上命令会将 "test-index" 索引的 "title" 和 "content" 字段都设置为文本类型。
4.查看索引
curl -X GET -u elastic:密码 "localhost:9200/_cat/indices?v"