centos http es 创建索引
时间: 2023-08-31 12:10:28 浏览: 119
在 CentOS 上使用 Elasticsearch 创建索引的步骤如下:
1. 首先,确保已经安装了 Elasticsearch。如果没有安装,可以通过以下命令安装:
```
sudo yum install elasticsearch
```
2. 启动 Elasticsearch 服务:
```
sudo systemctl start elasticsearch
```
3. 创建一个名为 my_index 的索引:
```
curl -XPUT 'localhost:9200/my_index?pretty'
```
4. 创建一个包含字段的映射:
```
curl -H 'Content-Type: application/json' -XPUT 'localhost:9200/my_index/_mapping?pretty' -d '{
"properties": {
"field1": {"type": "text"},
"field2": {"type": "keyword"}
}
}'
```
在这里,我们创建了一个包含两个字段的映射:field1 和 field2。field1 的类型是 text,而 field2 的类型是 keyword。
5. 添加文档到索引中:
```
curl -H 'Content-Type: application/json' -XPOST 'localhost:9200/my_index/_doc?pretty' -d '{
"field1": "This is some text",
"field2": "keyword"
}'
```
这将添加一个文档到 my_index 索引中,包含两个字段:field1 和 field2。
6. 搜索索引:
```
curl -XGET 'localhost:9200/my_index/_search?q=field1:this&pretty'
```
这将搜索 my_index 索引,查找包含字段 field1 中包含单词 "this" 的文档。
以上就是在 CentOS 上使用 Elasticsearch 创建索引的基本步骤。如果需要更复杂的索引操作,可以参考 Elasticsearch 的官方文档。
阅读全文
相关推荐

















