Business intelligence made simple
Use multi search format for Elasticsearch
Andrew Kane225cdfc8a6f7
diff --git a/lib/blazer/adapters/elasticsearch_adapter.rb b/lib/blazer/adapters/elasticsearch_adapter.rbindex 34607ea5..485f999d 100644--- a/lib/blazer/adapters/elasticsearch_adapter.rb+++ b/lib/blazer/adapters/elasticsearch_adapter.rb@@ -7,10 +7,11 @@ module Blazererror = nilbegin- response = client.search(body: JSON.parse(statement))+ header, body = statement.gsub(/\/\/.+/, "").strip.split("\n", 2)+ response = client.msearch(body: [JSON.parse(header), JSON.parse(body)])["responses"].firsthits = response["hits"]["hits"]source_keys = hits.flat_map { |r| r["_source"].keys }.uniq- hit_keys = ["_score", "_id", "_index", "_type"]+ hit_keys = (hits.first.try(:keys) || []) - ["_source"]columns = source_keys + hit_keysrows =hits.map do |r|@@ -29,7 +30,7 @@ module Blazerenddef preview_statement- '{"query": {"match_all": {}}, "size": 10}'+ %!// header\n{"index": "{table}"}\n\n// body\n{"query": {"match_all": {}}, "size": 10}!endprotected