创建索引
您可以使用以下命令创建索引-
curl -X PUT 'localhost:9200/weather'
响应
如果创建了索引,则可以看到以下输出-
{
"acknowledged": true,
"shards_acknowledged": true,
"index": "school"
}
新增数据
Elasticsearch将存储我们添加到索引中的文档,如以下代码所示。给文档提供了一些ID,这些ID用于识别文档。
请求正文
curl -X POST 'localhost:9200/school/_doc/10' -H 'content-Type:application/json' -d '
{
"name":"Saint Paul School",
"description":"ICSE Afiliation",
"street":"Dawarka",
"city":"Delhi",
"state":"Delhi",
"zip":"110075",
"location":[28.5733056, 77.0122136],
"fees":5000,
"tags":["Good Faculty", "Great Sports"],
"rating":"4.5"
}'
响应
{
"_index": "school",
"_type": "_doc",
"_id": "10",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
在这里,我们添加了另一个类似的文档。
curl -X POST 'localhost:9200/school/_doc/16' -H 'content-Type:application/json' -d
{
"name":"Crescent School", "description":"State Board Affiliation",
"street":"Tonk Road",
"city":"Jaipur", "state":"RJ", "zip":"176114","location":[26.8535922,75.7923988],
"fees":2500, "tags":["Well equipped labs"], "rating":"4.5"
}
响应
{
"_index": "school",
"_type": "_doc",
"_id": "16",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 1,
"_primary_term": 1
}
这样,我们将在接下来的章节中继续添加工作所需的任何示例数据。