elasticsearch - 多层嵌套映射和查询上的“Mapping definition has unsupported parameters”错误

标签 elasticsearch nested-queries elasticsearch-nested

我是Elasticsearch的新手。
我嵌套了数据。用户->汽车。
我在编写嵌套映射时需要帮助。

我已经看到了有关嵌套查询的ES网站和我能做的基本网站。我为深度2/3创建映射时遇到麻烦。

我正在尝试创建以下映射,但似乎无法正常工作。

我需要能够查询如下内容:
给我所有文件users.usertype=salariedcars.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"
                }
            ]
        }
    ]
}
yearmake属性应该在同一对象中,而不是分开的

关于elasticsearch - 多层嵌套映射和查询上的“Mapping definition has unsupported parameters”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57069108/

相关文章:

mysql - 如何在 MySQL 中选择最近 30 天的日期?

elasticsearch - Elasticsearch按数组字段中的对象中的多个字段过滤

elasticsearch - 嵌套 Elasticsearch 嵌套查询问题 ES7.2

elasticsearch - 如何在没有正则表达式的情况下使用脚本字段从日志字段中搜索子字符串

c# - NEST Elasticsearch :FilterInputs术语和术语之间的区别?

elasticsearch - Elasticsearch:嵌套映射在搜索上引发错误

java - elasticsearch 6.3.2 的 NestedSortBuilder 使用示例

elasticsearch - 在ElasticSearch中查询动态对象类型

elasticsearch - Elasticsearch 部分快照如何工作

sql - 如何优化嵌套查询?