1

hi i am using elasticsearch to index some documents. but the documents will have some fileds like goal1Completion, goal2Completion....goal100Completion. so i was trying to do mapping with dynamic Templates. so i came up with following but it throws an error:

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

what could be thee problem here?

1 Answer 1

1

You need to pull dynamic_template from properties map.

{
 "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"
              }
           }
          }
       ]
     }
  }
 }
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks .just figured it out
but this solution dosent works error is gone but the mapping of goalXXcompletion is still string it should be long type as defined in mapping above
I tried to run Following query. POST index/date {"goal2completion":"abcde"} . Assigning string to goalXXcompletion. I got the error : {"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"} That implies dynamic template is working.
its wierd even i get the same error when indexing that means mapping is correct but while qurying i get this error: RequestError: TransportError(400, u'search_phase_execution_exception', u'Expected numeric type on field [ga:goal2Completions], but got [string]')
What query are you running?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.