Template file not working in ElasticSearch -
i have external json template file load elasticsearch
this do:
curl -xput 'http://localhost:9200/_template/mytemplate' -d @file.json
the command correctly acknowledged
unfortunately when index created rules defined inside json file not applied
edit
this json file
{ "template" : "log-*", "settings": { "index": { "number_of_shards": 1, "number_of_replicas": 0 } }, "mappings": { "logevent": { "properties": { "timestamp": { "type": "date", "format": "dateoptionaltime" }, "message": { "type": "string" }, "messageobject": { "type": "object" }, "exception": { "type": "object" }, "loggername": { "type": "string" }, "domain": { "type": "string" }, "identity": { "type": "string" }, "level": { "type": "string" }, "classname": { "type": "string" }, "filename": { "type": "string" }, "linenumber": { "type": "long" }, "fullinfo": { "type": "string" }, "methodname": { "type": "string" }, "fix": { "type": "string" }, "username": { "type": "string" }, "threadname": { "type": "string" }, "hostname": { "type": "string" } } } } }
which should applied index matching log-*
. 1 of index log-2016.07.28
the template specifies type of linenumber
. should change type of such linenumber
field default string
long
. document linenumber
string
.
this returned document:
{ "took" : 1, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "log-2016.07.28", "_type" : "logevent", "_id" : "avywvw-k6ghup7t-syll", "_score" : 1.0, "_source" : { "timestamp" : "2016-07-28t09:04:02.8994786z", "message" : "upload file operation took 600 ms", "messageobject" : { }, "exception" : { }, "loggername" : "reviewer.web.webapi.groupscontroller", "domain" : "/lm/w3svc/2/root-1-131141667495593380", "identity" : "", "level" : "info", "classname" : "reviewer.logger.methodtimer", "filename" : "methodtimer.cs", "linenumber" : "49", "fullinfo" : "methodtimer.cs:49)", "methodname" : "dispose", "fix" : "locationinfo, username, identity, partial", "properties" : { "test" : "123", "log4net:hostname" : "gbwotiom68052d", "ip" : "::1", "log4net:identity" : "", "log4net:username" : "corp\\gianluca.ghettini", "log4net:elapsedtime" : "600", "@timestamp" : "2016-07-28t09:04:02.8994786z" }, "username" : "corp\\gianluca.ghettini", "threadname" : "198", "hostname" : "gbwotiom68052d" } } ] } }
as can see
"linenumber" : "49",
is still string
instead of long
what observe source of document (as sent es) , es never change it. if source contains string value, you'll see string value, if source contains numeric value, you'll see number value in source.
however, way data indexed matters. if mapping declares given field string, field value in source (be number, boolean, string or whatever) indexed string.
if mapping declares given field number , field value in source string, es try coerce string number , number indexed, however, the string in source not changed number.
so, in case, send linenumber
string "49"
, es coerce string "49"
number 49
, index number, though, source still contain string "49"
.
to sum up, if want see number in source, need send number, i.e. "linenumber": 49
instead of "linenumber": "49"
Comments
Post a Comment