Fixed the ES inline script

WIthin this change the ceilometer_resource index in ES
is being created and updated on a query sent from
ceilometer_collector periodically, as the inline script
got fixed. Without this fix, the ES cluster will produce huge
amout of logs, errors, in elasticsearch.log, which can lead
to disk space fillup.

Second fix is in the resources.lua, where we get rid of
'\'\ character present in the field names.
bad:
meters.volume\size\type
good:
meters.volume.size.type

Change-Id: Id084b3c451f0db6fd40cc62de448bb84f18316ed
Closes-Bug: PROD-18143
diff --git a/heka/files/lua/common/elasticsearch_resources.lua b/heka/files/lua/common/elasticsearch_resources.lua
index b77caa6..3bf5bdd 100644
--- a/heka/files/lua/common/elasticsearch_resources.lua
+++ b/heka/files/lua/common/elasticsearch_resources.lua
@@ -36,26 +36,32 @@
             update = {_index = index, _type = type_name, _id = resource_id}
         })
         local body = {
-            script = 'ctx._source.meters += meter;' ..
-            'ctx._source.user_id = user_id;' ..
-            'ctx._source.project_id = project_id;' ..
-            'ctx._source.source = source; ' ..
-            'ctx._source.metadata =  ' ..
-            'ctx._source.last_sample_timestamp <= timestamp ? ' ..
-            'metadata : ctx._source.metadata;' ..
-            'ctx._source.last_sample_timestamp = ' ..
-            'ctx._source.last_sample_timestamp < timestamp ?' ..
-            'timestamp : ctx._source.last_sample_timestamp;' ..
-            'ctx._source.first_sample_timestamp = ' ..
-            'ctx._source.first_sample_timestamp > timestamp ?' ..
-            'timestamp : ctx._source.first_sample_timestamp;',
-            params = {
-                meter = resource.meter,
-                metadata = resource.metadata,
-                timestamp = resource.timestamp,
-                user_id = resource.user_id or '',
-                project_id = resource.project_id or '',
-                source = resource.source or '',
+            script = {
+                source = 'def SDF = new SimpleDateFormat(\"yyyy-MM-dd\'T\'HH:mm:ss.SSSSSSXXX\"); ' ..
+                         'ctx._source.meters.putAll(params.meter); ' ..
+                         'ctx._source.user_id = params.user_id; ' ..
+                         'ctx._source.project_id = params.project_id; ' ..
+                         'ctx._source.source = params.source; ' ..
+                         'ctx._source.metadata = ' ..
+                         'SDF.parse(ctx._source.last_sample_timestamp).getTime() <= ' ..
+                         'SDF.parse(params.timestamp).getTime() ? ' ..
+                         'params.metadata : ctx._source.metadata; ' ..
+                         'ctx._source.last_sample_timestamp = ' ..
+                         'SDF.parse(ctx._source.last_sample_timestamp).getTime() < ' ..
+                         'SDF.parse(params.timestamp).getTime() ? ' ..
+                         'params.timestamp : ctx._source.last_sample_timestamp; ' ..
+                         'ctx._source.first_sample_timestamp = ' ..
+                         'SDF.parse(ctx._source.first_sample_timestamp).getTime() > ' ..
+                         'SDF.parse(params.timestamp).getTime() ?' ..
+                         'params.timestamp : ctx._source.first_sample_timestamp;',
+                params = {
+                    meter = resource.meter,
+                    metadata = resource.metadata,
+                    timestamp = resource.timestamp,
+                    user_id = resource.user_id or '',
+                    project_id = resource.project_id or '',
+                    source = resource.source or '',
+                }
             },
             upsert = {
                 first_sample_timestamp = resource.timestamp,
diff --git a/heka/files/lua/common/resources.lua b/heka/files/lua/common/resources.lua
index 0a32ac2..4a37815 100644
--- a/heka/files/lua/common/resources.lua
+++ b/heka/files/lua/common/resources.lua
@@ -64,7 +64,7 @@
 }
 
 function add_resource_to_payload(sample, payload)
-    local counter_name, _ = string.gsub(sample.counter_name, "%.", "\\")
+    local counter_name, _ = sample.counter_name
 
     local metadata = sample.resource_metadata
     local local_metadata = {}