【问题标题】:elasticsearch mapping exception when using dynamic templates使用动态模板时的elasticsearch映射异常
【发布时间】:2017-05-15 18:48:33
【问题描述】:

您好,我正在使用弹性搜索来索引一些文档。但文件会有一些文件,如goal1Completiongoal2Completion....goal100Completion。所以我试图用dynamic Templates 进行映射。所以我想出了以下但它抛出了一个错误:

{
  "mappings": {
    "date": {
      "properties": {
        "sessions": {
          "type": "long"
        },
        "viewId": {
          "type": "string",
          "index": "not_analyzed"
        },
        "webPropertyId": {
          "type": "string",
          "index": "not_analyzed"
        },
        "dynamic_templates": [
          {
            "goalCompletions": {
              "match_pattern": "regex",
              "match": "goal\\d+\\w+",
              "mapping": {
                "type": "long"
              }
            }
          }
        ]
      }
    }
  }
}



error:"reason": "Expected map for property [fields] on field [dynamic_templates] but got a class java.lang.String"

你有什么问题吗?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您需要从properties 映射中提取dynamic_template

    {
     "mappings": {
      "date": {
         "properties": {
            "sessions": {
               "type": "long"
            },
            "viewId": {
               "type": "string",
               "index": "not_analyzed"
            },
            "webPropertyId": {
               "type": "string",
               "index": "not_analyzed"
            }
         },
         "dynamic_templates": [                 <--- Pull this out of properties
            {
               "goalCompletions": {
                  "match_pattern": "regex",
                  "match": "goal\\d+\\w+",
                  "mapping": {
                     "type": "long"
                  }
               }
              }
           ]
         }
      }
     }
    

    【讨论】:

    • 谢谢。刚刚想通了
    • 但是这个解决方案dosent works错误消失了但是goalXXcompletion的映射仍然是string它应该是上面映射中定义的长类型
    • 我尝试运行以下查询。 POST index/date {"goal2completion":"abcde"} 。将字符串分配给goalXXcompletion。我得到了错误:{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse [goal2completion]"}],"type":"mapper_parsing_exception","reason":"failed to parse [goal2completion]","caused_by":{"type":"number_format_exception","reason":"For input string: \"10skfhkds\""}},"status":400} {"goal2completion":"abcde"} 这意味着动态模板正在工作。
    • 它很奇怪,即使我在索引时得到同样的错误,这意味着映射是正确的,但是在查询时我得到这个错误:RequestError: TransportError(400, u'search_phase_execution_exception', u'Expected numeric type on field [ga:goal2Completions], but got [string]')
    • 你在运行什么查询?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-05-28
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-05
    相关资源
    最近更新 更多