是否可以在elasticsearch中为字段名设置别名?(就像索引名可以设置别名一样)例如:我有一个文档{'firstname':“约翰”,"姓“:“铁匠”}我想把“firstname”改成“fn "
pzfprimi1#
只是一个快速的更新,Elasticsearch 6.4提出了一个名为**Alias Datatype**的功能。检查下面的Map和查询作为示例。请注意,在以下fieldname fn的Map中,字段的类型为alias
6.4
fn
alias
PUT myindex { "mappings": { "_doc": { "properties": { "firstname": { "type": "text" }, "fn": { "type": "alias", "path": "firstname" } } } } }
GET myindex/_search { "query": { "match" : { "fn" : "Steve" } } }
我们的想法是将alias用于创建倒排索引的实际字段。请注意,具有别名数据类型的字段不用于write操作,它仅用于查询目的。虽然你可以参考我提到的链接了解更多细节,但以下只是一些要点。
write
single mapping
6.xx
index.mapping.single_type: true
querying
aggregations
sorting
highlighting
suggestion
_source
mu0hgdu02#
没有直接的字段别名功能。但是,您可以在使用Map中的index_name属性建立索引时重命名字段。索引名称:将存储在索引中的字段的名称。默认为属性/字段名称。有关详细信息,请参阅此处:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html
ggazkfy83#
正在为现有字段firstname添加别名fn
firstname
PUT myindex/_mapping { "properties": { "fn": { "type": "alias", "path": "firstname" } } }
从Elasticsearch 7开始应该这样工作。
ilmyapht4#
也许你可以尝试在你的索引上创建一个别名,并在所需的字段上使用过滤器。你的过滤器必须以这样的方式编写,它可以从你的字段中选择所有的条目。请参考here中的过滤别名部分。但是我很想知道你的用例。为什么你要在特定的字段上创建别名。
4条答案
按热度按时间pzfprimi1#
只是一个快速的更新,Elasticsearch
6.4
提出了一个名为**Alias Datatype**的功能。检查下面的Map和查询作为示例。请注意,在以下fieldname
fn
的Map中,字段的类型为alias
样本Map:
示例查询:
我们的想法是将
alias
用于创建倒排索引的实际字段。请注意,具有别名数据类型的字段不用于write
操作,它仅用于查询目的。虽然你可以参考我提到的链接了解更多细节,但以下只是一些要点。
single mapping
时使用。索引必须在6.xx
之后的版本中创建,或者在设置为index.mapping.single_type: true
的旧版本中创建querying
、aggregations
、sorting
、highlighting
和suggestion
操作alias
字段的alias
alias
。单一别名,单一字段。*不能用作使用
_source
的源筛选的一部分。mu0hgdu02#
没有直接的字段别名功能。但是,您可以在使用Map中的index_name属性建立索引时重命名字段。
索引名称:将存储在索引中的字段的名称。默认为属性/字段名称。
有关详细信息,请参阅此处:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html
ggazkfy83#
正在为现有字段
firstname
添加别名fn
从Elasticsearch 7开始应该这样工作。
ilmyapht4#
也许你可以尝试在你的索引上创建一个别名,并在所需的字段上使用过滤器。你的过滤器必须以这样的方式编写,它可以从你的字段中选择所有的条目。请参考here中的过滤别名部分。但是我很想知道你的用例。为什么你要在特定的字段上创建别名。