二十六 mapping root object深入剖析

本文深入探讨了Elasticsearch中的rootobject概念,包括其映射JSON结构、properties、metadata如_id、_source、_type,以及setting配置如analyzer和include_in_all。详细讲解了_source字段的好处,如直接获取完整文档、部分更新、reindex操作、定制返回field和debugquery便利性,以及如何禁用_source。同时介绍了_all字段的作用和如何在field级别设置include_in_all。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • root object

就是某个type对应的mapping json,包括如下几种:

1. properties

2. metadata(_id, _source, _type)

3. setting(analyzer)

4. 其它settings(比如include_in_all)

例如:

PUT /my_index
{
  "mappings": {
    "my_type": {
      "properties": {}  ---这个就是properties
    }
  }
}

  • properties

properties又包含了type,index,analyzer等,例如:

PUT /my_index/_mapping/my_type
{
  "properties": {
    "title": {
      "type": "text"
    }
  }
}

  • _source

好处

(1)查询的时候,直接可以拿到完整的document,不需要先拿document id,再发送一次请求拿document
(2)partial update基于_source实现
(3)reindex时,直接基于_source实现,不需要从数据库(或者其他外部存储)查询数据再修改
(4)可以基于_source定制返回field
(5)debug query更容易,因为可以直接看到_source

如果不需要上述好处,可以禁用_source

PUT /my_index/_mapping/my_type2
{
  "_source": {"enabled": false}
}

  • _all

将所有field打包在一起,作为一个_all field,建立索引。没指定任何field进行搜索时,就是使用_all field在搜索。

PUT /my_index/_mapping/my_type3
{
  "_all": {"enabled": false}
}

也可以在field级别设置include_in_all field,设置是否要将field的值包含在_all field中

PUT /my_index/_mapping/my_type4
{
  "properties": {
    "my_field": {
      "type": "text",
      "include_in_all": false
    }
  }
}

  • 标识性metadata

_index,_type,_id

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值