ElasticSearch最佳入门实践(十五)_document的_source元数据以及定制返回结果解析

_index元数据

  • 表明一个document存放在哪一个index中
  • 相似的数据放在一个索引中,非相似的数据放在不一样的索引中:product index(包含了全部的商品)、sales index(包含了全部的商品销售数据)、inventory index(包含了全部库存的相关数据)
  • index中包含了不少相似的document: 相似是什么意思呢,其实指的就是说,这些document的fields很大一部分是相同的,你说你放了3个document,每一个document的fields都彻底不同,这就不是相似了,就不太适合放到一个index里面去了
  • 索引名称必须是小写,不能用下划线开头,不包含逗号

_type元数据

  • 表明document属于index的哪一个类别
  • 一个索引一般会划分为多个type,逻辑上对index有些许不一样的几类数据进行分类
  • type名称能够是大写或者小写,可是同时不能用下划线开头,不能包含逗号

_id元数据

  • 表明document的惟一标识,与_index和_type一块儿能够起惟一标识和定位一个document
  • 咱们能够手动指定document的id,也能够不指定,由es自动为咱们建立一个id

1、_source元数据

创建一条数据

put /test_index/test_type/1
{
  "test_field1": "test_field1",
  "test_field2": "test_field2"
}

get /test_index/test_type/1

{
  "_index": "test_index",
  "_type": "test_type",
  "_id": "3",
  "_version": 1,
  "found": true,
  "_source": {
    "test_field1": "test_field1",
    "test_field2": "test_field2"
  }
}

_source元数据:就是说,我们在创建一个document的时候,使用的那个放在request body中的json串,默认情况下,在get的时候,会原封不动的给我们返回回来。



定制返回的结果,指定_source中,返回哪些field

GET /test_index/test_type/1?_source=test_field1,test_field2

{
  "_index": "test_index",
  "_type": "test_type",
  "_id": "1",
  "_version": 2,
  "found": true,
  "_source": {
    "test_field2": "test_field2"
  }
}

在这里插入图片描述

在这里插入图片描述

2、定制返回结果

定制返回的结果,指定_source中,返回哪些field。多个可用用 , 分割

在这里插入图片描述

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值