【问题标题】:How to create a sub object in Elastic-search 7.x如何在 Elastic-search 7.x 中创建子对象
【发布时间】:2019-06-19 17:46:49
【问题描述】:

之前我使用的是 1.x 版本并使用以下语法创建子对象映射。

"foo": {
            "type": "integer",
            "doc_values": true
        },
"foo.bar": {
            "type": "integer",
            "doc_values": true
        },
"foo.bar.baz": {
            "type": "integer",
            "doc_values": true
        },

但是现在当我在 ES 7.x 中使用相同的映射语法时,我遇到了以下错误:-

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Can't merge a non object mapping [foo] with an object mapping [foo]"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Can't merge a non object mapping [foo] with an object mapping [foo]"
    },
    "status": 400
}

我来到了这个 SO 帖子 Can’t merge a non object mapping with an object mapping error in machine learning(beta) module 但是,请注意,我没有更新映射,而是创建了一个新映射,但仍然出现此错误,请告知该怎么做?

【问题讨论】:

    标签: elasticsearch elasticsearch-mapping


    【解决方案1】:

    对象类型的示例。更多信息请参考here

    "mappings": {
        "properties": { 
          "user": { 
            "properties": {
              "age":  { "type": "integer" },
              "name": { 
                "properties": {
                  "first": { "type": "text" },
                  "last":  { "type": "text" }
                }
              }
            }
          }
        }
    

    在下面的名称可以定义为对象,并且可以使用 name.firstname 等添加更多属性。在您的映射中,foo 是整数类型,然后您添加 foo.bar,因此它会引发错误。 foo 必须是对象类型。

    "properties" : {
                "name" : {
                    "type" : "object"
                },
                "name.firstname":{
                  "type" : "text"
                },
                "name.lastname":{
                  "type" : "text"
                }
            }
    

    【讨论】:

    • 我研究了这个,但是在这种格式下,我必须更改很多,我想知道它是否有可能与现有格式一起使用
    • 感谢您提供一些简单的语法,但它仍然需要一些更改,我想知道为什么它在 ES 1.x 中有效,而我没有看到这方面有任何重大更改
    • 在 1.x 中映射语法类似于 7 。我无法理解它是如何工作的。 elastic.co/guide/en/elasticsearch/guide/1.x/…
    • 这正是我的担心,因为它涉及到很多我想避免的语法更改
    • elastic.co/guide/en/elasticsearch/reference/2.4/…。根据这篇文章,您将不得不更新映射到对象类型
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 2012-01-04
    • 2020-04-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多