es:http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/_indexing_employee_documents.html
下一篇博客:http://my.oschina.net/qiangzigege/blog/263627
内容:
第一任务是存储雇员数据,一个文档代表一个雇员,
es里的存储叫做索引。
需要决定在哪存储。
在es里,一个文档属于一个type,很多types在一个index里。
和关系型数据库比较如下:
Relational DB Databases Tables Rows Columns
Elasticsearch Indices Types Documents Fields
一个index表示一个数据库,
一个es集群里可以有多个索引,每个索引包含多个types.
每个type包含多个documents,每个document包含多个fields.
索引每一个文档
每个文档的type: employee
每个文档的index: megacorp
集群:
PUT /megacorp/employee/1
{
"first_name" : "John",
"last_name" : "Smith",
"age" : 25,
"about" : "I love to go rock climbing",
"interests": [ "sports", "music" ]
}
the path /megacorp/employee/1 包含三个信息。
megacorp ---index
employee ---type
1 ---雇员ID
请求体则包含雇员信息。
这里并没有直接建立索引,一切都在后台默认方式进行。
再添加一些文档。
PUT /megacorp/employee/2
{
"first_name" : "Jane",
"last_name" : "Smith",
"age" : 32,
"about" : "I like to collect rock albums",
"interests": [ "music" ]
}
PUT /megacorp/employee/3
{
"first_name" : "Douglas",
"last_name" : "Fir",
"age" : 35,
"about": "I like to build cabinets",
"interests": [ "forestry" ]
}