术语差异

关系型数据库 Elasticsearch
Database Index
Table Type
Row/Record Document
Column Name field

上表粗略地描述了关系数据库和 elasticsearch 的基本元素之间的类比。

建立

考虑关系数据库中的以下结构:

create databse test;

use test;

create table product;

create table product (name varchar, id int PRIMARY KEY);

insert into product  (id,name) VALUES (1,'Shirt');

insert into product  (id,name) VALUES (2,'Red Shirt');

select * from product;

name      | id 
----------+----
Shirt     |  1
Red Shirt |  2

Elasticsearch 等效:

POST test/product
{
    "id" : 1,
    "name" : "Shirt"
}

POST test/product
{
    "id" : 2,
    "name" : "Red Shirt"
}

GET test/product/_search

"hits": [
     {                                      ==============
        "_index": "test",                   ===> index    |
        "_type": "product",                 ===>type      |
        "_id": "AVzglFomaus3G2tXc6sB",                    |
        "_score": 1,                                      |
        "_source": {                                      |===> document
           "id": 2,                        ===>field      | 
           "name": "Red Shirt"             ===>field      |
        }                                                 |
     },                                     ==============
     {
        "_index": "test",
        "_type": "product",
        "_id": "AVzglD12aus3G2tXc6sA",
        "_score": 1,
        "_source": {
           "id": 1,                 
           "name": "Shirt"           
        }
     }
  ]