curl 'localhost:9200/students/stu/1?pretty'
结果:
{
"_index" : "students",
"_type" : "stu",
"_id" : "1",
"_version" : 1,
"found" : true,
"_source" : {
"id" : "1",
"name" : "中华人民共和国"
}
}
2. 查看index的内容 如curl 'localhost:9200/students?pretty'
{
"students" : {
"aliases" : { },
"mappings" : {
"stu" : {
"properties" : {
"id" : {
"type" : "string" //类型id
},
"name" : {
"type" : "string" //字段name string类型
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1475633663838",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "z8SNOI2tTHKO0G2mYfmFzg",
"version" : {
"created" : "2030599"
}
}
},
"warmers" : { }
}
}
3. 查看全部索引curl 'localhost:9200/_cat/indices?v'
4. 查询index为area的全部数据
curl -XPOST 'localhost:9200/area/_search?pretty' -d '
{
"query":{"match_all":{}}
}'
5. 索引和mapping的创建
1.ES的mapping非常类似于静态语言中的数据类型:声明一个变量为int类型的变量, 以后这个变量都只能存储int类型的数据。同样的, 一个number类型的mapping字段只能存储number类型的数据。
2.
(1)创建索引 curl -X PUT http://localhost:9200/account
(2)创建如下mapping
curl -X PUT http://localhost:9200/account/stu/_mapping -d '{
"stu": {
"_all": {
"analyzer": "ik_smart",
"search_analyzer": "ik_smart",
"term_vector": "no",
"store": "false"
},
"properties": {
"sid": {
"type": "string"
},
"name": {
"type": "string"
},
"age": {
"type": "string"
},
"sex": {
"type": "string"
},
"address": {
"type": "string"
},
"telePhone": {
"type": "nested"
},
"persionList": {
"type": "nested"}
}
}
}'