使用动态模板时弹性搜索映射异常

时间:2017-05-15 10:39:42

标签: elasticsearch

您好我正在使用elasticsearch索引某些文档。但文档会有一些文件,如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"

这可能是什么问题?

1 个答案:

答案 0 :(得分:1)

您需要从dynamic_template地图中提取properties

{
 "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"
              }
           }
          }
       ]
     }
  }
 }