|
@@ -8,16 +8,22 @@ module Blazer
|
|
|
|
|
|
begin
|
|
|
header, 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
|
|
|
+ end
|
|
|
rescue => e
|
|
|
error = e.message
|
|
|
end
|