Elasticsearch字段名称别名 [英] Elasticsearch field name aliasing
问题描述
是否可以在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'...
推荐答案
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
创建索引
- 可以在
querying
,aggregations
,sorting
,highlighting
和suggestion
操作中使用 - 目标字段必须是在其上创建倒排索引的实际字段
- 无法创建另一个
alias
字段的alias
- 不能在多个字段上使用
alias
.单一别名,单一字段. - 不能用作作为使用
_source
进行源过滤的一部分.
- Field alias is only meant to be used when your index has a
single mapping
. Index has to be created post6.xx
version or be created in older version with the settingindex.mapping.single_type: true
- Can be used in
querying
,aggregations
,sorting
,highlighting
andsuggestion
operations - Target field must be actual field on which inverted index is created
- Cannot create
alias
of anotheralias
field - Cannot use
alias
on multiple fields. Single alias, Single field. - Cannot be used as part of source filtering using
_source
.
这篇关于Elasticsearch字段名称别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!