diff --git a/README.md b/README.md index f6bcbcf..a5a07e2 100644 --- a/README.md +++ b/README.md @@ -13,15 +13,16 @@ Here is an example HTML file defining a Kendo grid talking to ElasticSearch: ElasticSearch Kendo DataSource example - + + - - - - + + + + - - + + @@ -40,6 +41,9 @@ Here is an example HTML file defining a Kendo grid talking to ElasticSearch: // point it to the URL where ElasticSearch search requests can go transport: { read: { + //other urls: + // http://localhost:9200/logstash-*/_search/ + // http://localhost:9200/index1,index2,index3/_search/ url: "http://localhost:9200/_all/_search/" } }, @@ -51,10 +55,12 @@ Here is an example HTML file defining a Kendo grid talking to ElasticSearch: model: { fields: { message: { type: "string" }, + event_data_timestamp: { type:"datetime", esName:"event.data.timestamp"}, + other: { type:"string"}, // you can specify a different ElasticSearch name for the field, // to deal with ElasticSearch field names that Kendo can't handle - timestamp: { type: "date", esName: "@timestamp" } + timestamp: { type: "datetime", esName: "@timestamp" } } } }, @@ -62,7 +68,15 @@ Here is an example HTML file defining a Kendo grid talking to ElasticSearch: // server-side paging, filtering and sorting are enabled by default. // Set filters as you like sort: { field: "timestamp", dir: "desc" }, - filter: { field: "message", operator: "eq", value: "accepted" } + filter: [ + { + "logic":"and", + "filters":[ + { field: "message", operator: "eq", value: "accepted" }, + { field: "other", operator: "neq", value: "0" } + ] + } + ] }), // other grid options besides the datasource @@ -71,7 +85,9 @@ Here is an example HTML file defining a Kendo grid talking to ElasticSearch: filterable: true, columns: [ { field: "timestamp" }, - { field: "message" } + { field: "message" }, + { field: "event_data_timestamp"}, + { field: "other"} ] }); }); diff --git a/kendo-elasticsearch.js b/kendo-elasticsearch.js index 6df0e02..db238b6 100644 --- a/kendo-elasticsearch.js +++ b/kendo-elasticsearch.js @@ -1,3 +1,4 @@ + /** * A Kendo DataSource that gets its data from ElasticSearch. * @@ -72,7 +73,18 @@ dataItem.id = hits[i]._id; for (var k in self._esFieldMap) { - dataItem[k] = hitSource[self._esFieldMap[k]]; + var nameSplit = self._esFieldMap[k].split("."); + if (nameSplit.length > 1) { + var temp = hitSource; + for (var l in nameSplit) { + temp = temp[nameSplit[l]]; + if (temp == undefined) + break; + } + dataItem[k] = temp; + } + else + dataItem[k] = hitSource[self._esFieldMap[k]]; } dataItems.push(dataItem); @@ -162,4 +174,4 @@ } }) -})(window.kendo); +})(window.kendo); \ No newline at end of file