ElasticSearch数据及其使用

时间:2021-03-15 10:34:48   收藏:0   阅读:0

引言


NoSql:主要指非关系型、分布式、不提供ACID的数据库设计模式。

1 ES总结

1.1 功能

全文检索、结构化搜索、分析

1.2 数据的输入和输出

1.2.1 ES是分布式的文档存储
1.2.2 什么是文档
{
    "name":         "John Smith",
    "age":          42,
    "confirmed":    true,
    "join_date":    "2014-06-01",
    "home": {
        "lat":      51.5,
        "lon":      0.1
    },
    "accounts": [
        {
            "type": "facebook",
            "id":   "johnsmith"
        },
        {
            "type": "twitter",
            "id":   "johnsmith"
        }
    ]
}
1.2.3 文档元数据

文档在哪存放

一个索引名必须小写,不能以下划线开头,不能包含逗号。

文档表示的对象类别

一个 _type 命名可以是大写或者小写,但是不能以下划线或者句号开头,不应该包含逗号, 并且长度限制为256个字符。

文档唯一标识

ID 是一个字符串,当它和 _index 以及 _type 组合就可以唯一确定 Elasticsearch 中的一个文档。 当创建一个新的文档,要么提供自己的 _id ,要么让 Elasticsearch 帮你生成。

1.2.4 索引文档
# 索引请求格式
--------------------------------------------------------------

PUT /{index}/{type}/{id}
{
  "field": "value",
  ...
}
    
--------------------------------------------------------------
    
PUT /website/blog/123
{
  "title": "My first blog entry",
  "text":  "Just trying this out...",
  "date":  "2014/01/01"
}

# 响应体
--------------------------------------------------------------

{
   "_index":    "website",
   "_type":     "blog",
   "_id":       "123",
   "_version":  1,
   "created":   true
}
# 索引请求格式
--------------------------------------------------------------

POST /{index}/{type}/{id}
{
  "field": "value",
  ...
}
    
--------------------------------------------------------------
    
POST /website/blog/
{
  "title": "My second blog entry",
  "text":  "Still trying this out...",
  "date":  "2014/01/01"
}

# 响应体
--------------------------------------------------------------

{
   "_index":    "website",
   "_type":     "blog",
   "_id":       "AVFgSgVHUP18jI2wRx0w",
   "_version":  1,
   "created":   true
}

‘‘‘
自动生成的 ID 是 URL-safe、 基于 Base64 编码且长度为20个字符的 GUID 字符串。 这些 GUID 字符串由可修改的 FlakeID 模式生成,这种模式允许多个节点并行生成唯一 ID ,且互相之间的冲突概率几乎为零。
‘‘‘
1.2.5 取回一个文档
GET /website/blog/123?pretty
{
  "_index" :   "website",
  "_type" :    "blog",
  "_id" :      "123",
  "_version" : 1,
  "found" :    true,
  "_source" :  {
      "title": "My first blog entry",
      "text":  "Just trying this out...",
      "date":  "2014/01/01"
  }
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!