This repository was archived by the owner on Nov 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 139
[WIP] (#63) Add a /stats sub-endpoint #181
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bbfa345
[WIP] (#63) Add a /stats sub-endpoint
siruguri eb4ed82
Add integration test for /stats sub-endpoint
siruguri ba2d44a
Merge branch 'dev' into siruguri-stats-endpoint
siruguri f93aece
Incorporate fdbk from PR
siruguri 375cb34
Merge branch 'dev' into siruguri-stats-endpoint
siruguri b662c95
Fix spec definition that compares hashes
siruguri 82235dd
Delete generated CSS files
siruguri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -242,6 +242,3 @@ DEPENDENCIES | |
| safe_yaml | ||
| sass | ||
| stretchy | ||
|
|
||
| BUNDLED WITH | ||
| 1.10.6 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,12 +76,20 @@ def self.search(terms, options = {}) | |
| body: query_body | ||
| } | ||
|
|
||
| # Per https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html: | ||
| # "the search_type and the query_cache must be passed as query-string parameters" | ||
| if options[:command] == 'stats' | ||
| full_query.merge! :search_type => 'count' | ||
| end | ||
|
|
||
| logger.info "FULL_QUERY: #{full_query.inspect}" | ||
|
|
||
| time_start = Time.now.to_f | ||
| result = client.search full_query | ||
|
|
||
| search_time = Time.now.to_f - time_start | ||
| logger.info "ES query time (ms): #{result["took"]} ; Query fetch time (s): #{search_time} ; result: #{result.inspect[0..500]}" | ||
|
|
||
| hits = result["hits"] | ||
| total = hits["total"] | ||
| results = [] | ||
|
|
@@ -97,7 +105,7 @@ def self.search(terms, options = {}) | |
|
|
||
| found.keys.each { |key| found[key] = found[key][0] } | ||
| # now it should look like this: | ||
| # {"city"=>"Springfield", "address"=>"742 Evergreen Terrace | ||
| # {"city"=>"Springfield", "address"=>"742 Evergreen Terrace} | ||
|
|
||
| # re-insert null fields that didn't get returned by ES | ||
| query_body[:fields].each do |field| | ||
|
|
@@ -118,10 +126,28 @@ def self.search(terms, options = {}) | |
| end | ||
|
|
||
| # assemble a simpler json document to return | ||
| simple_result = | ||
| { | ||
| "metadata" => metadata, | ||
| "results" => results | ||
| } | ||
|
|
||
| if options[:command] == 'stats' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be broken out into its own method. (We should refactor the rest of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I'm guessing each of the 3 |
||
| # Remove metrics that weren't requested. | ||
| aggregations = result['aggregations'] | ||
| aggregations.each do |f_name, values| | ||
| if options[:metrics] && options[:metrics].size > 0 | ||
| aggregations[f_name] = values.reject { |k, v| !(options[:metrics].include? k) } | ||
| else | ||
| # Keep everything is no metric list is provided | ||
| aggregations[f_name] = values | ||
| end | ||
| end | ||
|
|
||
| simple_result.merge!({"aggregations" => aggregations}) | ||
| end | ||
|
|
||
| simple_result | ||
| end | ||
|
|
||
| private | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # cities100.txt | ||
| # Test YAML file | ||
| index: numeric-data | ||
| api: cities | ||
|
|
||
| dictionary: | ||
| name: | ||
| source: name | ||
| type: string | ||
| address: | ||
| source: address | ||
| type: string | ||
| city: | ||
| source: city | ||
| type: string | ||
| age: | ||
| source: age | ||
| type: integer | ||
| height: | ||
| source: height | ||
| type: float |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like how you've refactored this, thank you!