我是Elasticsearch的新手。
我嵌套了数据。用户->汽车。
我在编写嵌套映射时需要帮助。
我已经看到了有关嵌套查询的ES网站和我能做的基本网站。我为深度2/3创建映射时遇到麻烦。
我正在尝试创建以下映射,但似乎无法正常工作。
我需要能够查询如下内容:
给我所有文件users.usertype=salaried
和cars.make=honda
。
这是我的映射:
{
"mappings": {
"properties": {
"users": {
"type": "nested",
"usertype": {
"type": "text"
},
"cars": {
"type": "nested",
"properties": {
"make": {
"type": "text"
},
"model": {
"type": "text"
}
}
}
}
}
}
}
这是我的示例数据:
{
"users": [
{
"usertype": "salaried",
"cars": [
{
"make": "honda"
},
{
"year": "2016"
}
]
},
{
"usertype": "business",
"cars": [
{
"make": "BMW"
},
{
"year": "2018"
}
]
}
]
}
创建映射时出现以下错误:
"caused_by": {
"type": "mapper_parsing_exception",
"reason": "Mapping definition for [user] has unsupported parameters: [details : {type=nested, properties={make={type=text}}}]"
}
最佳答案
您应将usertype
定义为users
字段的属性,如下所示:
{
"mappings": {
"properties": {
"users": {
"type": "nested",
"properties": {
"usertype": {
"type": "text"
},
"cars": {
"type": "nested",
"properties": {
"make": {
"type": "text"
},
"model": {
"type": "text"
}
}
}
}
}
}
}
}
我认为您的样本数据中应该有一个问题
{
"users": [
{
"usertype": "salaried",
"cars": [
{
"make": "honda",
"year": "2016"
}
]
},
{
"usertype": "business",
"cars": [
{
"make": "BMW",
"year": "2018"
}
]
}
]
}
year
和make
属性应该在同一对象中,而不是分开的
关于elasticsearch - 多层嵌套映射和查询上的“Mapping definition has unsupported parameters”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57069108/