elasticsearch之索引文档和取回文档

2018-10-22  本文已影响0人  煮茶boy

文档: 多数实体或对象可以被序列化为包含键值对的 JSON 对象,文档是指最顶层或者根对象, 这个根对象被序列化成 JSON 并存储到 Elasticsearch 中,指定了唯一 ID。

文档元数据: 一个文档不仅仅包含它的数据 ,也包含元数据 —— 有关*文档的信息。

索引文档

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

取回一个文档

GET /index/type/id?pretty    --- pretty格式化输出,是输出结果更加美观

GET /website/blog/123?pretty

{
  "_index" :   "website",
  "_type" :    "blog",
  "_id" :      "123",
  "_version" : 1,
  "found" :    true,
  "_source" :  {      ---- '_source'字段里面就是我们需要的JSON数据
      "title": "My first blog entry",
      "text":  "Just trying this out...",
      "date":  "2014/01/01"
  }
}
GET /website/blog/123?_source=title,text

{
  "_index" :   "website",
  "_type" :    "blog",
  "_id" :      "123",
  "_version" : 1,
  "found" :   true,
  "_source" : {
      "title": "My first blog entry" ,
      "text":  "Just trying this out..."
  }
}
GET /website/blog/123/_source

{
   "title": "My first blog entry",
   "text":  "Just trying this out...",
   "date":  "2014/01/01"
}
上一篇下一篇

猜你喜欢

热点阅读