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

查看:1808
本文介绍了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.

请注意,在以下字段名称为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.

  • 仅当索引具有single mapping时才使用字段别名.必须在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天全站免登陆