使用curl操作ElasticSearch初步

1. 列明现有的所有index

curl -XGET ‘localhost:9200/_cat/indices?v’
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
yellow open .kibana bndJD_c9RYGzu7XuWDyK9w 1 1 2 0 8.4kb 8.4kb

2. 创建新的index

curl -XPUT ‘localhost:9200/customer?pretty’

{
“acknowledged” : true,
“shards_acknowledged” : true,
“index” : “customer”
}

3. 添加文档、查询文档
curl -XPUT ‘localhost:9200/customer/doc/1?pretty&pretty’ -H ‘Content-Type: application/json’ -d’

> {
> “name”: “John Doe”
> }
> ‘
{
“_index” : “customer”,
“_type” : “doc”,
“_id” : “1”,
“_version” : 1,
“result” : “created”,
“_shards” : {
“total” : 2,
“successful” : 1,
“failed” : 0
},
“_seq_no” : 0,
“_primary_term” : 1
}

# query
curl -XGET ‘localhost:9200/customer/doc/1?pretty&pretty’

{
“_index” : “customer”,
“_type” : “doc”,
“_id” : “1”,
“_version” : 1,
“found” : true,
“_source” : {
“name” : “John Doe”
}
}

Leave Comment

电子邮件地址不会被公开。 必填项已用*标注