ElasticSearch52:索引管理_mapping root object深入剖析

1.root object是什么?
就是某个type对应的mapping json,包括properties,metadata(_id,_source,_type),settings(analyzer),其他settings(比如include_in_all)

其中,下面的{
            "properties":{
            }
            ...
        }
        这部分就是mapping的root object对象

PUT /my_index
{
    "mappings":{
        "my_type":{
            "properties":{
            }
            ...
        }
    }
}


下面来讲解一下root object有什么?
2.properties
配置type里面的document有哪些field:field的type(类型),index(是否进行分词),analyzer(分词器)

PUT /my_index/my_type/_mapping
{
    "my_type":{
        "properties":{
            "title":{
                "type":"text",
                "index":"analyzed",
                "analyzed":"standard"
            }
        }
    }
}

例子:

PUT /index0/my_type/_mapping
{
  "properties": {
    "title":{
      "type": "text",
      "index": true,
      "analyzer": "standard"
    }
  }
}


3._source
就是我们在保存document,最原始的json的文本,就是作为document的_source的值。
好处:
1)查询的时候,直接可以拿到完整的document,不需要先拿document id,再发送一次请求拿document
2)partial update基于_source实现
3)reindex时,直接基于_source实现,不需要从数据(或者其他外部存储)查询数据再修改,后面学习零停机重建索引
4)可以基于_source定制返回field
5)debug query更容易,因为可以直接看到_source

如果你不需要上述的好处,可以禁用_source
PUT /my_index
{
    "mappings":{
        "my_type":{
            "_source":{
                "enabled":false
            }
        }
    }
}



例子:如果是已经存在的type,是无法再修改enabled的属性的。
修改my_type2成功
PUT /index0/my_type2/_mapping
{
  "_all": {"enabled":false}
}

修改以及存在的my_type失败
PUT /index0/_mapping/my_type
{
  "_all": {"enabled":false}
}
执行结果:
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "mapper [_all] enabled is true now encountering false"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "mapper [_all] enabled is true now encountering false"
  },
  "status": 400
}


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

如果你不需要,可以禁用
PUT /index0/_mapping/my_type
{
    "_all":{
        "enabled":false
    }
}



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

PUT /my_index/my_type/_mapping
{
    "my_field":{
    }
}

例子:
PUT /index0/_mapping/my_type2
{
  "properties": {
    "title":{
      "type": "text",
      "include_in_all": false
    }
  }
}

同样的,不能对已经存在的type进行操作,必须是新的type,上面的type的title是存在于同一个index的其他的type中的,前面我们了解了type的底层,所以报错了
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "Mapper for [title] conflicts with existing mapping in other types:\n[mapper [title] has different [analyzer], mapper [title] is used by multiple types. Set update_all_types to true to update [search_analyzer] across all types., mapper [title] is used by multiple types. Set update_all_types to true to update [search_quote_analyzer] across all types.]"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "Mapper for [title] conflicts with existing mapping in other types:\n[mapper [title] has different [analyzer], mapper [title] is used by multiple types. Set update_all_types to true to update [search_analyzer] across all types., mapper [title] is used by multiple types. Set update_all_types to true to update [search_quote_analyzer] across all types.]"
  },
  "status": 400
}

我们重新建立一个type
PUT /index0/_mapping/my_type4
{
  "properties": {
    "content11":{
      "type": "text",
      "include_in_all": false
    }
  }
}

执行成功
执行结果:
{
  "acknowledged": true
}

修改my_type的字段content12(新字段),也可以执行成功
PUT /index0/my_type/_mapping
{
  "properties": {
    "content12":{
      "type": "text",
      "include_in_all": false
    }
  }
}

执行结果:
{
  "acknowledged": true
}


5.标识性metadata
_index, _type, _id
是document的metadata













  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据引用\[1\]中的错误信息,TypeError: __new__() missing 1 required positional argument: 'is_raw',这个错误通常是由于在创建一个新的对象时,缺少了一个必需的参数is_raw导致的。根据引用\[3\]中的代码,可以看出这个错误是在创建一个RawDataElement对象时发生的。可能是在调用这个对象的构造函数时,没有正确地传递dataset_root参数导致的。 另外,根据引用\[2\]中的描述,也有可能是由于Python库版本不兼容导致的。作者在使用es库时,Python版本为8.1.0,而本地es服务器版本为8.1.1。为了解决这个问题,作者将本地es服务器版本降级到了5.1.1,并将Python的es库版本降级到了5.1.0,这样问题就得到了解决。 综上所述,解决TypeError: __init__() missing 1 required positional argument: 'dataset_root'的方法是确保在创建RawDataElement对象时正确传递了dataset_root参数,并且检查Python库的版本兼容性。 #### 引用[.reference_title] - *1* *3* [TypeError: __new__() missing 1 required positional argument: ‘is_raw](https://blog.csdn.net/m0_60568871/article/details/127291889)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [已解决 | python 操作 elasticsearch TypeError: __init__() missing 1 required positional argument: ...](https://blog.csdn.net/shaotianyang12/article/details/125098389)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值