mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
- More histogram work.
- Have LogStash::Search::ElasticSearch#histogram yield an error if one occurs - /api/histogram reports an error now if 'q' param is missing
This commit is contained in:
parent
e8f43c15d2
commit
d674dd475e
3 changed files with 22 additions and 6 deletions
|
@ -122,14 +122,22 @@ class LogStash::Search::ElasticSearch < LogStash::Search::Base
|
|||
result.duration = Time.now - start_time
|
||||
|
||||
@logger.info(["Got search results",
|
||||
{ :query => query.query_string, :duration => data["duration"],
|
||||
:results => data["hits"]["hits"].size }])
|
||||
{ :query => query.query_string, :duration => data["duration"] }])
|
||||
if req.response_header.status != 200
|
||||
result.error_message = data["error"] || req.inspect
|
||||
@error = data["error"] || req.inspect
|
||||
end
|
||||
|
||||
data["facets"]["amazingpants"]["entries"].each do |entry|
|
||||
entries = data["facets"]["amazingpants"]["entries"] rescue nil
|
||||
|
||||
if entries.nil? or !data["error"].nil?
|
||||
# Use the error message if any, otherwise, return the whole
|
||||
# data object as json as the error message for debugging later.
|
||||
result.error_message = (data["error"] rescue false) || data.to_json
|
||||
yield result
|
||||
next
|
||||
end
|
||||
entries.each do |entry|
|
||||
# entry is a hash of keys 'total', 'mean', 'count', and 'key'
|
||||
hist_entry = LogStash::Search::FacetResult::Histogram.new
|
||||
hist_entry.key = entry["key"]
|
||||
|
|
|
@ -9,8 +9,8 @@ class LogStash::Search::FacetResult::Histogram < LogStash::Search::FacetResult::
|
|||
attr_accessor :total
|
||||
attr_accessor :count
|
||||
|
||||
# sometimes a parent call to to_json calls us with args?
|
||||
def to_json(*args)
|
||||
p :to_json => args
|
||||
return {
|
||||
"key" => @key,
|
||||
"mean" => @mean,
|
||||
|
|
|
@ -163,6 +163,11 @@ class LogStash::Web::Server < Sinatra::Base
|
|||
|
||||
aget '/api/histogram' do
|
||||
headers({"Content-Type" => "text/plain" })
|
||||
if params[:q].nil?
|
||||
status 500
|
||||
body({ "error" => "No query given (missing 'q' parameter)" }.to_json)
|
||||
next
|
||||
end
|
||||
format = (params[:format] or "json")
|
||||
field = (params[:field] or "@timestamp")
|
||||
interval = (params[:interval] or 3600 * 1000)
|
||||
|
@ -175,15 +180,18 @@ class LogStash::Web::Server < Sinatra::Base
|
|||
end
|
||||
|
||||
begin
|
||||
p results.results.class
|
||||
a = results.results.to_json
|
||||
rescue => e
|
||||
status 500
|
||||
body e.inspect
|
||||
p :exception => e
|
||||
p e
|
||||
raise e
|
||||
end
|
||||
status 200
|
||||
body a
|
||||
end # @backend.search
|
||||
end # apost '/api/search'
|
||||
end # aget '/api/histogram'
|
||||
|
||||
aget '/*' do
|
||||
status 404 if @error
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue