A question on dynamic templates

I am putting in custom templates to take the guess work out of the mappings generated. The indices are created daily and collect logs. I took the mapping of one of the created index and then added the dynamic template section in it. Then I posted it back into the elasticsearch. Should I have removed the sections which would now be handled by dynamic template?

Details
The field is Result.NumericValue

Now it can have say 34 as well as 67.56. Depending on the contents of the first log of the day, Result.NumericValue would get mapped as a long or a double. If it gets mapped as long then it rejects the values like 67.56.

So I wrote a dynamic template:

"dynamic_templates": [
  {
	"full_name": {
	  "path_match": "*.NumericValue",
	  "mapping": {
		"type": "float"
	  }
	}
  }
],

The existing template has sections like this

"type" : {
  "properties" : {
	"numericValue" : {
	  "type" : "float"
	}
  }
}

Should I remove them before pushing it in elasticsearch. Till now I have refrained from doing so. Does it make a difference? Or does dynamic template has higher precedence?

The mapping in the template has precedence before the dynamic template. In this case it does not matter though, so you could just remove it.

Thanks for quick reply. Will do that.

One question just to make things clear for myself.

Lets assume that the existing mapping was long.

"type" : {
  "properties" : {
	"numericValue" : {
	  "type" : "long"
	}
  }
}

If Result.NumericValue comes with a value 34.65 then based on above template, elasticsearch will reject it because mapping in template has the precedence over the dynamic template section of it. Right?
Despite a dynamic template section which would have mapped this as a float.

Sorry for so many edits to answers.

You can check via

DELETE foo

PUT foo
{
  "mappings": {
    "dynamic_templates": [
      {
        "full_name": {
          "path_match": "value",
          "mapping": {
            "type": "float"
          }
        }
      }
    ],
    "properties": {
      "value": {
        "type": "long"
      }
    }
  }
}

GET foo/_mapping/field/value

Sorry for late reply. And I am bit confused now. I am able to put both 34 and 34.34 in the index using this mapping !! Should it not have refused 34.34 ??

POST foo/_doc/
{
  "value" : 34
}

POST foo/_doc/
{
  "value" : 34.34
}

GET foo/_search

Results contain both the values.

"hits" : [
  {
    "_index" : "foo",
    "_type" : "_doc",
    "_id" : "6vP4UXEBMk4Pt2X_nero",
    "_score" : 1.0,
    "_source" : {
      "value" : 34
    }
  },
  {
    "_index" : "foo",
    "_type" : "_doc",
    "_id" : "dE_4UXEBRU_resXUqMei",
    "_score" : 1.0,
    "_source" : {
      "value" : 34.34
    }
  }
]

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.