elasticsearch Alias field type 使用注意事项
-
- Alias field type
- 注意事项
-
- The target must be a concrete field, and not an object or another field alias.
- The target field must exist at the time the alias is created.
- If nested objects are defined, a field alias must have the same nested scope as its target.
- A field alias can only have one target
- Attempting to use an alias in an index or update request will result in a failure.
- aliases cannot be used as the target of copy_to
- Because alias names are not present in the document source, aliases cannot be used when performing source filtering
- end
Alias field type
啥也不说,先附上文档链接
https://www.elastic.co/guide/en/elasticsearch/reference/7.17/field-alias.html#field-alias
本次就做一次 alias 的注意事项笔记,希望对大伙(不爱翻官方文档的)有点帮助(o゜▽゜)o☆[BINGO!]
首先简要描述一下 Alias 。它是别名,为索引中的字段定义替代名称,可以对别名搜索达到搜索映射来源的效果。
注意事项
那么正文开始:
Alias targetsedit
There are a few restrictions on the target of an alias:
The target must be a concrete field, and not an object or another field alias.
目标必须是一个明确的字段,不能是一个object对象或者其它别名。
错误尝试:指定的目标为 object
ps(name目标由于没有指定类型,且是一个json对象,所以是一个object类型)
PUT alias_test
{
"mappings": {
"properties": {
"name_content": {
"type": "alias",
"path": "name"
},
"name": {
"first": "John",
"last": "Smith"
}
}
}
}
*********************result*************************
{
"error" : {
"root_cause" : [
{
"type" : "mapper_parsing_exception",
"reason" : "No type specified for field [name]"
}
],
"type" : "mapper_parsing_exception",
"reason" : "Failed to parse mapping [_doc]: No type specified for field [name]",
"caused_by" : {
"type" : "mapper_parsing_exception",
"reason" : "No type specified for field [name]"
}
},
"status" : 400
}
错误尝试:指定的目标为 其它的别名
由于别名本身并不会作为真实字段进行存储与_source,所以当指定的目标为其它别名时,所报的提示错误会和指定了一个不存在字段的错误信息一致。
PUT alias_test
{
"mappings": {
"properties": {
"name_content": {
"type": "alias",
"path": "name"
},
"name": {
"type": "alias",
"path": "name_content"
}
}
}
}
*********************result********