【发布时间】:2018-10-10 06:17:44
【问题描述】:
假设有一个索引,其中包含描述车辆的文档。
您的索引需要处理两种不同类型的车辆:摩托车和汽车。
从性能的角度来看,以下哪个映射更好? (出于我的目的需要嵌套)
"vehicle": {
"type": "nested",
"properties": {
"car": {
"properties": {
"model": {
"type": "string"
},
"cost": {
"type": "integer"
}
}
},
"motorcycle": {
"properties": {
"model": {
"type": "string"
},
"cost": {
"type": "integer"
}
}
}
}
}
或者这个:
"vehicle": {
"type": "nested",
"properties": {
"model": {
"type": "string"
},
"cost": {
"type": "integer"
},
"vehicle_type": {
"type": "string" ### "car", "motorcycle"
}
}
}
第二个更易读,更薄。
但我的缺点是,当我进行查询时,如果我只想关注“汽车”,我需要将此条件作为查询的一部分。
如果我使用第一个映射,我只需要直接访问存储的字段,而不会增加查询的开销。
【问题讨论】:
标签: elasticsearch