是否可以在elasticsearch中为字段名设置别名?(就像索引名称的别名一样)
例如:我有一个文档{'firstname':'John','lastname':'smith'}
我想将'firstname‘别名为'fn'...
发布于 2018-10-16 00:33:34
这只是一个快速更新,Elasticsearch 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操作,它仅用于查询目的。
虽然你可以参考我提到的链接了解更多细节,但下面只是一些重要的要点。
single mapping时使用。索引必须在版本后创建,或在旧版本中使用设置index.mapping.single_type: truequerying,aggregations,sorting,highlighting和suggestion创建。索引字段必须是其上已倒排索引的实际字段,并创建另一个代码字段的alias < 6.xx >H127querying>不能对多个字段使用<aggregations>D28alias >。单个别名、单个field._source.的源过滤的一部分使用
发布于 2015-02-13 19:20:09
没有直接的字段别名功能。但是,您可以在索引时使用映射中的index_name属性重命名字段。
index_name :将存储在索引中的字段的名称。默认为属性/字段名称。
更多信息请看这里:http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-core-types.html
发布于 2020-04-14 18:25:33
为现有字段firstname添加别名fn
PUT myindex/_mapping
{
"properties": {
"fn": {
"type": "alias",
"path": "firstname"
}
}
}从Elasticsearch 7开始应该是这样工作的。
https://stackoverflow.com/questions/28497771
复制相似问题