elastic_mini_query 0.1.0alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +29 -0
  3. data/.docker-env.skel +1 -0
  4. data/.gitignore +14 -0
  5. data/.rspec +3 -0
  6. data/.travis.yml +7 -0
  7. data/CODE_OF_CONDUCT.md +74 -0
  8. data/Gemfile +6 -0
  9. data/Gemfile.lock +39 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +66 -0
  12. data/Rakefile +6 -0
  13. data/bin/console +14 -0
  14. data/bin/rspec +14 -0
  15. data/bin/setup +8 -0
  16. data/docker-compose/rspec.yml +5 -0
  17. data/docker-compose.yml +23 -0
  18. data/docs/Usage.md +79 -0
  19. data/docs/class_diagram.drawio +1 -0
  20. data/elastic_mini_query.gemspec +44 -0
  21. data/lib/elastic_mini_query/client/base.rb +46 -0
  22. data/lib/elastic_mini_query/client/http_methods.rb +36 -0
  23. data/lib/elastic_mini_query/query/agg_builder.rb +23 -0
  24. data/lib/elastic_mini_query/query/builder.rb +31 -0
  25. data/lib/elastic_mini_query/query/request.rb +6 -0
  26. data/lib/elastic_mini_query/query/response.rb +24 -0
  27. data/lib/elastic_mini_query/query/search_builder.rb +7 -0
  28. data/lib/elastic_mini_query/result/agg_item.rb +18 -0
  29. data/lib/elastic_mini_query/result/agg_result.rb +32 -0
  30. data/lib/elastic_mini_query/result/raw.rb +15 -0
  31. data/lib/elastic_mini_query/result/raw_dialect_base.rb +18 -0
  32. data/lib/elastic_mini_query/result/raw_dialect_v00.rb +6 -0
  33. data/lib/elastic_mini_query/result/raw_dialect_v71.rb +6 -0
  34. data/lib/elastic_mini_query/result/raw_parser.rb +58 -0
  35. data/lib/elastic_mini_query/result/search_doc.rb +4 -0
  36. data/lib/elastic_mini_query/result/search_result.rb +7 -0
  37. data/lib/elastic_mini_query/result/summary.rb +8 -0
  38. data/lib/elastic_mini_query/version.rb +3 -0
  39. data/lib/elastic_mini_query.rb +17 -0
  40. metadata +148 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5f271eec6911154699bc9e116ccc4c29cde412cb499a43a2dbd18b8e218b5fe3
4
+ data.tar.gz: 7970a2977db2181f16c9114583f50e0139e25c620c3461940b4188503b65c227
5
+ SHA512:
6
+ metadata.gz: 0bf093e28079d4b7fbfc5b27fbe5ecf60e3ec8862ff4c956953c304212f80969bdbec3e4f145adf2d016c6422706b25b15de8e225a8efc5bdd06ffc0a8ee203e
7
+ data.tar.gz: 8df8b2f1d9cd1cf8cc69668cebf2bb0123b03c52840885643a6cd65878666350a94ab06e66630e82dcbe30af36c24d98629c717ba36286d0616123bf4a3c3d8d
@@ -0,0 +1,29 @@
1
+ # Use the latest 2.1 version of CircleCI pipeline processing engine, see https://circleci.com/docs/2.0/configuration-reference/
2
+ version: 2.1
3
+
4
+ executors:
5
+ base-rails:
6
+ working_directory: /app
7
+ docker:
8
+ - image: mosac/rails-start:2.6.3-rails5.2.3
9
+ - image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1
10
+ environment:
11
+ "discovery.type": "single-node"
12
+
13
+ jobs:
14
+ do-rspec:
15
+ executor: base-rails
16
+ steps:
17
+ - checkout
18
+ - run: while ! nc -z localhost 9200; do sleep 0.1; done
19
+ - run: /app/spec/es_scripts/7.x.start.sh
20
+ - run: bundle install
21
+ - run: bundle exec rspec
22
+
23
+ # Orchestrate or schedule a set of jobs, see https://circleci.com/docs/2.0/workflows/
24
+ workflows:
25
+ version: 2
26
+ rspec:
27
+ jobs:
28
+ - do-rspec
29
+
data/.docker-env.skel ADDED
@@ -0,0 +1 @@
1
+ ELASTIC_URL=
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # docker-compose
14
+ .docker-env*
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.17.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mobi.ysk.zusa+work@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in elastic_mini_query.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,39 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ elastic_mini_query (0.1.0)
5
+ faraday (~> 0.15.0, >= 0.10.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.3)
11
+ faraday (0.15.4)
12
+ multipart-post (>= 1.2, < 3)
13
+ multipart-post (2.1.1)
14
+ rake (10.5.0)
15
+ rspec (3.8.0)
16
+ rspec-core (~> 3.8.0)
17
+ rspec-expectations (~> 3.8.0)
18
+ rspec-mocks (~> 3.8.0)
19
+ rspec-core (3.8.1)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-expectations (3.8.4)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-mocks (3.8.1)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-support (3.8.2)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.17)
34
+ elastic_mini_query!
35
+ rake (~> 10.0)
36
+ rspec (~> 3.0)
37
+
38
+ BUNDLED WITH
39
+ 1.17.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 y_zusa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # ElasticMiniQuery
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/elastic_mini_query`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'elastic_mini_query'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install elastic_mini_query
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ### Test
34
+
35
+ ```sh
36
+ bundle exec rspec
37
+ ```
38
+
39
+ Or with docker-compose(recommended)
40
+
41
+ ```sh
42
+ docker-compose -f docker-compose.yml -f docker-compose/rspec.yml run app
43
+ ```
44
+
45
+ #### Loading Sample Data
46
+
47
+ * 7.x
48
+
49
+ ```sh
50
+ docker-compose exec elasticsearch /es_scripts/7.x.start.sh
51
+ ```
52
+
53
+
54
+ See: https://www.elastic.co/guide/en/kibana/7.1/tutorial-load-dataset.html
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/elastic_mini_query. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
63
+
64
+ ## Code of Conduct
65
+
66
+ Everyone interacting in the ElasticMiniQuery project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/elastic_mini_query/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "elastic_mini_query"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rspec ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ RED='\033[0;31m'
6
+ GREEN='\033[0;32m'
7
+ YELLOW='\033[1;33m'
8
+ CYAN='\033[0;36m'
9
+ RESET='\033[0m'
10
+
11
+ echo -e "${YELLOW}Installing bundled gem files...${RESET}"
12
+ bundle install -j4 --quiet
13
+ echo -e "${YELLOW}done${RESET}"
14
+ bundle exec rspec
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ version: "3"
2
+ services:
3
+ app:
4
+ entrypoint: /app/bin/rspec
5
+ command: ""
@@ -0,0 +1,23 @@
1
+ version: "3"
2
+ services:
3
+ app:
4
+ image: mosac/rails-start:2.6.3-rails5.2.3
5
+ working_dir: /app
6
+ env_file:
7
+ - .docker-env
8
+ entrypoint: ""
9
+ command: /bin/sh -c "bundle install && while true; do echo hello world; sleep 10; done"
10
+ depends_on:
11
+ - elasticsearch
12
+ volumes:
13
+ - ./:/app
14
+
15
+ elasticsearch:
16
+ image: docker.elastic.co/elasticsearch/elasticsearch:7.1.1
17
+ environment:
18
+ "discovery.type": "single-node"
19
+ ports:
20
+ - 9200:9200
21
+ - 9300:9300
22
+ volumes:
23
+ - ./spec/es_scripts:/es_scripts
data/docs/Usage.md ADDED
@@ -0,0 +1,79 @@
1
+ # Usage
2
+
3
+ ## Initialize Query Class
4
+
5
+ ```ruby
6
+ class ElasticSimpleQuery < ElasticMiniQuery::Client::Base
7
+ elastic_mini_host "http://localhost:9200"
8
+ elastic_mini_api_key "some api key"
9
+
10
+ end
11
+
12
+ esq = ElasticSimpleQuery.new
13
+ ```
14
+
15
+ ## Search
16
+
17
+ * all columns
18
+
19
+ ```ruby
20
+ esq.q("hello")
21
+ ```
22
+
23
+ * specify columns
24
+
25
+ ```ruby
26
+ esq.q("hello", columns: ["col_a", "col_b"])
27
+ ```
28
+
29
+ ## Aggregation
30
+
31
+ ```ruby
32
+ esq.agg
33
+ .by_date(:day, format: 'YYYY-mm-dd')
34
+ .filter(...)
35
+ .agg("col_a", type: [:min, :max, :avg])
36
+ ```
37
+
38
+ ## fetch responses
39
+
40
+ ```ruby
41
+ res = esq.q("hello")
42
+ res.docs.each do |row, info|
43
+ # data processing
44
+ end
45
+
46
+ ## other fetch methods.
47
+ res.fetch_all
48
+ res.fetch_page
49
+ ```
50
+
51
+ ### Response Types
52
+
53
+ ```ruby
54
+ res = esq.q("hello")
55
+
56
+ class QueryResponse
57
+ ```
58
+
59
+ #### Query Information
60
+
61
+ ```ruby
62
+ info = res.info
63
+
64
+ class ResponseSummary
65
+ ```
66
+
67
+ #### Search Results
68
+
69
+ ```ruby
70
+ search_result = res.docs
71
+ class SearchResult
72
+ ```
73
+
74
+ #### Aggregation Results
75
+
76
+ ```ruby
77
+ aggregation_result = res.aggs
78
+ class AggResult
79
+ ```
@@ -0,0 +1 @@
1
+ <mxfile modified="2019-06-23T01:48:16.930Z" host="www.draw.io" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/7.8.7 Chrome/58.0.3029.110 Electron/1.7.5 Safari/537.36" etag="JS_vDKMbjwGDAZ1HIiLU" version="10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2CZBupXXyjt8jVSZdwNfXHZAibPbox89k+owupi9/XUbN8AktgXqxb8JrIv+yfTPGtk1B1emH8yd0XiG/q5VzrnTU02b5hLKmNo7TaLovuj3ZC2h818fkYvv6Zvz5avmazR7pYTX7J7Th7lUbTjaSbzbaVBTGUCb71n3w6srdqu17G+Pp9KYtnTZTzR7Npiv6ciGHD46BdnToE91dd3Roz7zojk5b0+k79A17zaatL3RfTiX0GIa/ZWCj0wlxzy1w7CijTo2m0bTpSKEhUwZysaDTCYnENV+RerOWsVBQcGyBe3uEWvWxBQnSHfDUAl+4OpmQUu0e8tACHwDWRY7Hb8aGS03tsqh90GT/fAzoZEKytP+kXndM7jqZkETxKmd3nUxIrX6rp/d2bx/mOKgGj1/qxQtFQuWqXqgL3KfKDWXa9EYlHfwhHNTkUI4oS15YHX8gb3aFvlOkuYJIm6oFGrVX5HU9embSh9hcwc2i60BDxRTCrNo8DbbrZ7gCeYt/AA==</diagram></mxfile>
@@ -0,0 +1,44 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "elastic_mini_query/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "elastic_mini_query"
8
+ spec.version = ElasticMiniQuery::VERSION
9
+ spec.authors = ["Mosack"]
10
+ spec.email = [""]
11
+
12
+ spec.summary = %q{Elastic Search Simple aggregation/search Query library}
13
+ spec.description = %q{}
14
+ spec.homepage = "https://github.com/Mosac/elastic_mini_query"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = "https://github.com/Mosack/elastic_mini_query"
24
+ spec.metadata["changelog_uri"] = "https://github.com/Mosack/elastic_mini_query/releases"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_dependency "faraday", [">= 0.10.0", "~>0.15.0"]
40
+
41
+ spec.add_development_dependency "bundler", "~> 1.17"
42
+ spec.add_development_dependency "rake", "~> 10.0"
43
+ spec.add_development_dependency "rspec", "~> 3.0"
44
+ end
@@ -0,0 +1,46 @@
1
+ require_relative "http_methods"
2
+
3
+ module ElasticMiniQuery::Client
4
+ class Base
5
+ include ::ElasticMiniQuery::Client::HttpMethods
6
+
7
+ class << self
8
+ def elastic_mini_es_version(version)
9
+ @version = version
10
+ end
11
+ end
12
+
13
+ attr_accessor :size, :track_total_hits
14
+
15
+ def initialize
16
+ @size = 100
17
+ @track_total_hits = true
18
+ end
19
+
20
+ def request
21
+ b = ElasticMiniQuery::Query::Builder.new
22
+ b.size = size
23
+ b.track_total_hits = track_total_hits
24
+ yield b
25
+
26
+ res = http_post do |req|
27
+ req.url("/#{b.indices}/_search")
28
+ req.body = b.to_json
29
+ end
30
+
31
+ ElasticMiniQuery::Query::Response.new(ElasticMiniQuery::Result::Raw.new(res.body))
32
+ end
33
+ private :request
34
+
35
+ def build
36
+ b = ElasticMiniQuery::Query::Builder.new
37
+ yield b
38
+ b
39
+ end
40
+ private :build
41
+
42
+ def agg(type, name)
43
+ agg(type, name)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,36 @@
1
+ require "faraday"
2
+
3
+ module ElasticMiniQuery::Client
4
+ module HttpMethods
5
+ module ClassMethods
6
+ def elastic_mini_host(host=nil)
7
+ @host = host unless host.nil?
8
+ @host
9
+ end
10
+
11
+ def elastic_mini_api_key(key=nil)
12
+ @key = key unless key.nil?
13
+ @key
14
+ end
15
+
16
+ def faraday_client
17
+ Faraday.new(url: elastic_mini_host) do |conn|
18
+ conn.adapter :net_http
19
+ end
20
+ end
21
+ end
22
+
23
+ def self.included(base)
24
+ base.extend(ClassMethods)
25
+ end
26
+
27
+ def http_post
28
+ res = self.class.faraday_client.post do |req|
29
+ req.headers['Content-Type'] = 'application/json'
30
+ req.headers['Authorization'] = "ApiKey #{self.class.elastic_mini_api_key}"
31
+
32
+ yield req
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,23 @@
1
+ module ElasticMiniQuery
2
+ module Query
3
+ class AggBuilder
4
+ def initialize(type, name)
5
+ @type = type
6
+ @name = name
7
+
8
+ @aggs = []
9
+ end
10
+
11
+ def agg(field, as, types)
12
+ types = [types] unless types.is_a?(Array)
13
+ @aggs << {
14
+ field: field,
15
+ as: as,
16
+ types: types
17
+ }
18
+
19
+ self
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ require_relative "agg_builder"
2
+ require_relative "search_builder"
3
+
4
+ module ElasticMiniQuery
5
+ module Query
6
+ class Builder
7
+ attr_accessor :indices
8
+ attr_writer :size, :track_total_hits
9
+ def initialize
10
+ @searches = []
11
+ @aggs = []
12
+
13
+ @indice = "*"
14
+ end
15
+
16
+ def agg(type, name)
17
+ agg = ElasticMiniQuery::Query::AggBuilder.new(type, name)
18
+ @aggs << agg
19
+
20
+ agg
21
+ end
22
+
23
+ def to_json
24
+ {
25
+ size: @size,
26
+ track_total_hits: @track_total_hits
27
+ }.to_json
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,6 @@
1
+ module ElasticMiniQuery
2
+ module Query
3
+ class Request
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,24 @@
1
+ require "json"
2
+
3
+ module ElasticMiniQuery
4
+ module Query
5
+ class Response
6
+ def initialize(raw)
7
+ @raw = raw
8
+ @summary, @search, @aggs = @raw.parse
9
+ end
10
+
11
+ def summary
12
+ @summary
13
+ end
14
+
15
+ def search
16
+ @search
17
+ end
18
+
19
+ def aggs
20
+ @aggs
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,7 @@
1
+ module ElasticMiniQuery
2
+ module Query
3
+ class SearchBuilder
4
+
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module ElasticMiniQuery::Result
2
+ class AggItem
3
+ attr_reader :key, :key_as_string, :doc_count
4
+
5
+ def initialize(item_hash)
6
+ i = item_hash.dup
7
+ @key = i.delete("key")
8
+ @key_as_string = i.delete("key_as_string")
9
+ @doc_count = i.delete("doc_count")
10
+
11
+ @fields = i
12
+ end
13
+
14
+ def [](key)
15
+ @fields[key]["value"]
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ require "elastic_mini_query/result/agg_item"
2
+
3
+ module ElasticMiniQuery::Result
4
+ class AggResult
5
+
6
+ attr_accessor :aggregations
7
+
8
+ def aggs(bucket)
9
+ return @items if @items
10
+ @items = []
11
+ each_item(bucket) do |item|
12
+ @items << item
13
+ end
14
+
15
+ @items
16
+ end
17
+
18
+ def each(bucket)
19
+ each_item(bucket) do |item|
20
+ yield item
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def each_item(bucket)
27
+ @aggregations[bucket]["buckets"].each do |item|
28
+ yield ElasticMiniQuery::Result::AggItem.new(item)
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ module ElasticMiniQuery
2
+ module Result
3
+ class Raw
4
+ def initialize(es_response_text)
5
+ @es_response_text = es_response_text
6
+ end
7
+
8
+ def parse
9
+ return @summary, @search, @agg unless @parse_result.nil?
10
+ @parser = ElasticMiniQuery::Result::RawParser.new()
11
+ @summary, @search, @agg = @parser.parse(@es_response_text)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,18 @@
1
+ require_relative "raw_dialect_v00"
2
+ require_relative "raw_dialect_v71"
3
+
4
+ module ElasticMiniQuery
5
+ module Result
6
+ class RawDialectBase
7
+ class << self
8
+ def dialector(version)
9
+ case version
10
+ when :latest
11
+ return RawDialectV00.new
12
+ else
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ module ElasticMiniQuery
2
+ module Result
3
+ class RawDialectV00
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module ElasticMiniQuery
2
+ module Result
3
+ class RawDialectV71
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,58 @@
1
+ require "json"
2
+
3
+ module ElasticMiniQuery
4
+ module Result
5
+ class RawParser
6
+ def initialize(version: :latest)
7
+ @dialector = ElasticMiniQuery::Result::RawDialectBase.dialector(version)
8
+ end
9
+
10
+ def parse(response)
11
+ @json = JSON.parse(response)
12
+
13
+ summary = ElasticMiniQuery::Result::Summary.new
14
+ summary.took = took
15
+ summary.total_hits = total_hits
16
+ summary.timed_out = timed_out
17
+ summary.total_hits_relation = total_hits_relation
18
+
19
+ search = ElasticMiniQuery::Result::SearchResult.new
20
+ search.hits = hits
21
+ search.sources = sources
22
+
23
+ agg = ElasticMiniQuery::Result::AggResult.new
24
+ agg.aggregations = aggregations
25
+
26
+ return [summary, search, agg]
27
+ end
28
+
29
+ def took
30
+ @json["took"].to_i
31
+ end
32
+
33
+ def timed_out
34
+ @json["timed_out"]
35
+ end
36
+
37
+ def total_hits
38
+ @json["hits"]["total"]["value"].to_i
39
+ end
40
+
41
+ def total_hits_relation
42
+ @json["hits"]["total"]["relation"]
43
+ end
44
+
45
+ def hits
46
+ @json["hits"]["hits"]
47
+ end
48
+
49
+ def sources
50
+ @json["hits"]["hits"].map {|d| d["_source"]}
51
+ end
52
+
53
+ def aggregations
54
+ @json["aggregations"]
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,4 @@
1
+ module ElasticMiniQuery::Result
2
+ class SearchDoc
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ require "elastic_mini_query/result/search_doc"
2
+
3
+ module ElasticMiniQuery::Result
4
+ class SearchResult
5
+ attr_accessor :hits, :sources
6
+ end
7
+ end
@@ -0,0 +1,8 @@
1
+ module ElasticMiniQuery
2
+ module Result
3
+ class Summary
4
+
5
+ attr_accessor :took, :timed_out, :total_hits, :total_hits_relation
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module ElasticMiniQuery
2
+ VERSION = "0.1.0alpha"
3
+ end
@@ -0,0 +1,17 @@
1
+ require "elastic_mini_query/version"
2
+ require "elastic_mini_query/client/base"
3
+ require "elastic_mini_query/query/response"
4
+ require "elastic_mini_query/query/builder"
5
+ require "elastic_mini_query/result/raw"
6
+ require "elastic_mini_query/result/raw_parser"
7
+ require "elastic_mini_query/result/raw_dialect_base"
8
+ require "elastic_mini_query/result/summary"
9
+ require "elastic_mini_query/result/search_result"
10
+ require "elastic_mini_query/result/agg_result"
11
+
12
+
13
+ module ElasticMiniQuery
14
+ class Error < StandardError; end
15
+ # Your code goes here...
16
+
17
+ end
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: elastic_mini_query
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0alpha
5
+ platform: ruby
6
+ authors:
7
+ - Mosack
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-06-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.0
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.15.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.10.0
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: 0.15.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.17'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.17'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.0'
75
+ description: ''
76
+ email:
77
+ - ''
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".circleci/config.yml"
83
+ - ".docker-env.skel"
84
+ - ".gitignore"
85
+ - ".rspec"
86
+ - ".travis.yml"
87
+ - CODE_OF_CONDUCT.md
88
+ - Gemfile
89
+ - Gemfile.lock
90
+ - LICENSE.txt
91
+ - README.md
92
+ - Rakefile
93
+ - bin/console
94
+ - bin/rspec
95
+ - bin/setup
96
+ - docker-compose.yml
97
+ - docker-compose/rspec.yml
98
+ - docs/Usage.md
99
+ - docs/class_diagram.drawio
100
+ - elastic_mini_query.gemspec
101
+ - lib/elastic_mini_query.rb
102
+ - lib/elastic_mini_query/client/base.rb
103
+ - lib/elastic_mini_query/client/http_methods.rb
104
+ - lib/elastic_mini_query/query/agg_builder.rb
105
+ - lib/elastic_mini_query/query/builder.rb
106
+ - lib/elastic_mini_query/query/request.rb
107
+ - lib/elastic_mini_query/query/response.rb
108
+ - lib/elastic_mini_query/query/search_builder.rb
109
+ - lib/elastic_mini_query/result/agg_item.rb
110
+ - lib/elastic_mini_query/result/agg_result.rb
111
+ - lib/elastic_mini_query/result/raw.rb
112
+ - lib/elastic_mini_query/result/raw_dialect_base.rb
113
+ - lib/elastic_mini_query/result/raw_dialect_v00.rb
114
+ - lib/elastic_mini_query/result/raw_dialect_v71.rb
115
+ - lib/elastic_mini_query/result/raw_parser.rb
116
+ - lib/elastic_mini_query/result/search_doc.rb
117
+ - lib/elastic_mini_query/result/search_result.rb
118
+ - lib/elastic_mini_query/result/summary.rb
119
+ - lib/elastic_mini_query/version.rb
120
+ homepage: https://github.com/Mosac/elastic_mini_query
121
+ licenses:
122
+ - MIT
123
+ metadata:
124
+ allowed_push_host: https://rubygems.org
125
+ homepage_uri: https://github.com/Mosac/elastic_mini_query
126
+ source_code_uri: https://github.com/Mosack/elastic_mini_query
127
+ changelog_uri: https://github.com/Mosack/elastic_mini_query/releases
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">"
140
+ - !ruby/object:Gem::Version
141
+ version: 1.3.1
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.7.6
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Elastic Search Simple aggregation/search Query library
148
+ test_files: []