1.4 KiB
1.4 KiB
写入数据:
举例说明,在索引名称未item中添加一个类型名称为es,编号为3的数据
curl -XPUT 127.0.0.1:9200/item/es/3?pretty -H 'content-Type:application/json' -d '{"name": "bi", "age": 21}'
或
curl -XPOST 127.0.0.1:9200/item/es/3?pretty -H 'content-Type:application/json' -d '{"name": "bi", "age": 21}'
结果如下
{
"_index" : "item", ## 索引
"_type" : "es", ## 类型名称
"_id" : "3", ## 编号
"_version" : 1, ## 对该数据的第几次操作
"result" : "created", ## 因为之前没有,即创建
"_shards" : {
"total" : 2, ## 分片数
"successful" : 1, ## 分片成功次数
"failed" : 0 ## 分片失败数
},
"_seq_no" : 4, ## 序列编号
"_primary_term" : 1 ##
}
get数据
curl -XGET 127.0.0.1:9200/item/es/3?pretty
结果为
{
"_index" : "item",
"_type" : "es",
"_id" : "3",
"_version" : 1,
"_seq_no" : 4,
"_primary_term" : 1,
"found" : true,
"_source" : {
"name" : "bi",
"age" : 21
}
}
搜索数据
curl -XGET 127.0.0.1:9200/item/es/_search?pretty
返回的结果方在hints数组中,默认展示匹配到的前10条数据
精确搜索
curl -XGET 127.0.0.1:9200/item/es/_search?q=name:wang?pretty
curl -XGET 127.0.0.1:9200/item/es/_search?q=name:bi