Business intelligence made simple
Added support for Elasticsearch timeouts
Andrew Kane284499ca55b8
diff --git a/lib/blazer/adapters/elasticsearch_adapter.rb b/lib/blazer/adapters/elasticsearch_adapter.rbindex 485f999d..8872c57f 100644--- a/lib/blazer/adapters/elasticsearch_adapter.rb+++ b/lib/blazer/adapters/elasticsearch_adapter.rb@@ -8,16 +8,22 @@ module Blazerbeginheader, body = statement.gsub(/\/\/.+/, "").strip.split("\n", 2)- response = client.msearch(body: [JSON.parse(header), JSON.parse(body)])["responses"].first- hits = response["hits"]["hits"]- source_keys = hits.flat_map { |r| r["_source"].keys }.uniq- hit_keys = (hits.first.try(:keys) || []) - ["_source"]- columns = source_keys + hit_keys- rows =- hits.map do |r|- source = r["_source"]- source_keys.map { |k| source[k] } + hit_keys.map { |k| r[k] }- end+ body = JSON.parse(body)+ body["timeout"] ||= data_source.timeout if data_source.timeout+ response = client.msearch(body: [JSON.parse(header), body])["responses"].first+ if response["error"]+ error = response["error"]+ else+ hits = response["hits"]["hits"]+ source_keys = hits.flat_map { |r| r["_source"].keys }.uniq+ hit_keys = (hits.first.try(:keys) || []) - ["_source"]+ columns = source_keys + hit_keys+ rows =+ hits.map do |r|+ source = r["_source"]+ source_keys.map { |k| source[k] } + hit_keys.map { |k| r[k] }+ end+ endrescue => eerror = e.messageend