術語差異

關係型資料庫 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"           
        }
     }
  ]