Elasticsearch 字段名称别名 [英] Elasticsearch field name aliasing

查看:47
本文介绍了Elasticsearch 字段名称别名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 elasticsearch 中为字段名称设置别名?(就像索引名称的别名一样)

Is it possible to setup alias for field names in elasticsearch? (Just like how index names can be aliased)

例如:我有一个文档 {'firstname': 'John', 'lastname': 'smith'}

For example: i have a document {'firstname': 'John', 'lastname': 'smith'}

我想将 'firstname' 别名为 'fn'...

I would like to alias 'firstname' to 'fn'...

推荐答案

只是一个快速更新,Elasticsearch 6.4 提出了一个名为 别名数据类型.检查以下映射和查询作为示例.

Just a quick update, Elasticsearch 6.4 came up with feature called Alias Datatype. Check the below mapping and query as sample.

注意,在下面的映射中,字段的类型是 alias 字段名 fn

Note that the type of the field is alias in the below mapping for fieldname fn

PUT myindex
{
  "mappings": {
    "_doc": {
      "properties": {
        "firstname": {
          "type": "text"
        },
        "fn": {
          "type": "alias",
          "path": "firstname" 
        }
      }
    }
  }
}

示例查询:

GET myindex/_search
{
  "query": {
    "match" : {
      "fn" : "Steve"
    }
  }
}

这个想法是为创建倒排索引的实际字段使用 alias.请注意,具有别名数据类型的字段不适用于 write 操作,它仅用于查询目的.

The idea is to use the alias for actual field on which inverted index is created. Note that fields with alias datatype aren't meant for write operations and its only meant for querying purpose.

虽然您可以参考我提到的链接了解更多详细信息,但以下只是其中的一些要点.

Although you can refer to the link I've mentioned for more details, below are just some of the important points.

  • 字段别名仅在您的索引具有单一映射 时使用.索引必须在 6.xx 版本之后创建,或者在旧版本中使用设置 index.mapping.single_type: true
  • 创建
  • 可用于queryingaggregationssortinghighlightingsuggestion 运营
  • 目标字段必须是创建倒排索引的实际字段
  • 无法为另一个 alias 字段创建 alias
  • 不能在多个字段上使用 alias.单一别名,单一字段.
  • 不能使用作为使用 _source 进行源过滤的一部分.
  • Field alias is only meant to be used when your index has a single mapping. Index has to be created post 6.xx version or be created in older version with the setting index.mapping.single_type: true
  • Can be used in querying, aggregations, sorting, highlighting and suggestion operations
  • Target field must be actual field on which inverted index is created
  • Cannot create alias of another alias field
  • Cannot use alias on multiple fields. Single alias, Single field.
  • Cannot be used as part of source filtering using _source.

这篇关于Elasticsearch 字段名称别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆