elasticsearch Alias field type 使用注意事项

本文详细介绍了Elasticsearch中字段别名的使用注意事项,包括别名目标必须是具体字段、创建时目标字段必须存在、嵌套对象限制、别名不能有多个目标以及不能用于索引或更新请求等。通过示例展示了错误用法及可能的错误信息,提醒开发者在使用时避免这些常见问题。
摘要由CSDN通过智能技术生成

Alias field type

啥也不说,先附上文档链接
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/field-alias.html#field-alias

本次就做一次 alias 的注意事项笔记,希望对大伙(不爱翻官方文档的)有点帮助(o゜▽゜)o☆[BINGO!]

首先简要描述一下 Alias 。它是别名,为索引中的字段定义替代名称,可以对别名搜索达到搜索映射来源的效果。

注意事项

那么正文开始:
Alias targetsedit
There are a few restrictions on the target of an alias:

The target must be a concrete field, and not an object or another field alias.

目标必须是一个明确的字段,不能是一个object对象或者其它别名。
错误尝试:指定的目标为 object
ps(name目标由于没有指定类型,且是一个json对象,所以是一个object类型)

PUT alias_test
{
   
  "mappings": {
   
    "properties": {
   
      "name_content": {
   
        "type": "alias",
        "path": "name"
      },
      "name": {
   
        "first": "John",
        "last": "Smith"
      }
    }
  }
}

*********************result*************************

{
   
  "error" : {
   
    "root_cause" : [
      {
   
        "type" : "mapper_parsing_exception",
        "reason" : "No type specified for field [name]"
      }
    ],
    "type" : "mapper_parsing_exception",
    "reason" : "Failed to parse mapping [_doc]: No type specified for field [name]",
    "caused_by" : {
   
      "type" : "mapper_parsing_exception",
      "reason" : "No type specified for field [name]"
    }
  },
  "status" : 400
}

错误尝试:指定的目标为 其它的别名
由于别名本身并不会作为真实字段进行存储与_source,所以当指定的目标为其它别名时,所报的提示错误会和指定了一个不存在字段的错误信息一致。

PUT alias_test
{
   
  "mappings": {
   
    "properties": {
   
      "name_content": {
   
        "type": "alias",
        "path": "name"
      },
      "name": {
   
        "type": "alias",
        "path": "name_content"
      }
    }
  }
}

*********************result********
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值