在Kibana的Dev Tools中执行GET _cat/indices
,查询所有的索引。
我们可以看到movies数据集,movies在ES中称之为索引。
indices:[ˈɪndɪsiːz]
执行GET movies/_search
,查询movies的前几条数据。
{
"took" : 0,//消耗的时间
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {//命中的数据
"total" : {
"value" : 10000,//总共1w条数据
"relation" : "gte"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "movies",//索引名
"_type" : "_doc",//类型
"_id" : "2206",//ID
"_score" : 1.0,
"_source" : {//存放的具体数据
"@version" : "1",
"id" : "2206",
"year" : 1941,
"genre" : [
"Film-Noir",
"Mystery",
"Thriller"
],
"title" : "Suspicion"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2207",
"_score" : 1.0,
"_source" : {
"@version" : "1",
"id" : "2207",
"year" : 1939,
"genre" : [
"Drama"
],
"title" : "Jamaica Inn"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2208",
"_score" : 1.0,
"_source" : {
"@version" : "1",
"id" : "2208",
"year" : 1938,
"genre" : [
"Drama",
"Mystery",
"Thriller"
],
"title" : "Lady Vanishes, The"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2209",
"_score" : 1.0,
"_source" : {
"@version" : "1",
"id" : "2209",
"year" : 1937,
"genre" : [
"Crime",
"Thriller"
],
"title" : "Young and Innocent"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2210",
"_score" : 1.0,
"_source" : {
"@version" : "1",
"id" : "2210",
"year" : 1936,
"genre" : [
"Thriller"
],
"title" : "Sabotage"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2211",
"_score" : 1.0,
"_source" : {
"@version" : "1",
"id" : "2211",
"year" : 1936,
"genre" : [
"Thriller"
],
"title" : "Secret Agent"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2212",
"_score" : 1.0,
"_source" : {
"@version" : "1",
"id" : "2212",
"year" : 1934,
"genre" : [
"Drama",
"Thriller"
],
"title" : "Man Who Knew Too Much, The"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2213",
"_score" : 1.0,
"_source" : {
"@version" : "1",
"id" : "2213",
"year" : 1933,
"genre" : [
"Comedy",
"Musical"
],
"title" : "Waltzes from Vienna"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2214",
"_score" : 1.0,
"_source" : {
"@version" : "1",
"id" : "2214",
"year" : 0,
"genre" : [
"Thriller"
],
"title" : "Number Seventeen"
}
},
{
"_index" : "movies",
"_type" : "_doc",
"_id" : "2215",
"_score" : 1.0,
"_source" : {
"@version" : "1",
"id" : "2215",
"year" : 1931,
"genre" : [
"Comedy",
"Romance"
],
"title" : "Rich and Strange"
}
}
]
}
}
使用GET movies
查看movies的信息,可查看Mapping。
1、索引
Elasticsearch中的索引有多层的意思:
- 某一类文档的集合就构成了一个索引,类比到数据库就是一个数据库(或者数据库表);
- 它还描述了一个动作,就是将某个文档保存在elasticsearch的过程也叫索引;
- 倒排索引。
2、文档
具体的一条数据,类比到数据库就是一条记录。
3、类型
在7.0之前,一个Index可以创建多个类型。从7.0开始,一个索引只能创建一个类型,也就是 _doc。
DBMS | Elasticsearch |
---|---|
database(数据库) | Index(索引) |
table(数据表) | type(在7.0之后type为固定值_doc) |
Row(记录) | Document(文档) |
Column(列) | Field(属性) |
Schema(数据库表的约束) | Mapping(属性的约束) |
SQL | DSL(Descriptor Structure Language)[描述性结构化语言] |
4、自定义mapping
PUT my_index
{
"mappings": {
"doc": {
"dynamic": false,
"properties": {
"title": {
"type": "text"
},
"name": {
"type": "keyword"
},
"age": {
"type": "integer"
}
}
}
}
}
其中包含了 title、name、age三个字段。
本文由 guoxiaorui 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Aug 28, 2020 at 11:49 pm