Class: ElasticSearch::QueryBuilder
- Inherits:
-
Object
- Object
- ElasticSearch::QueryBuilder
- Defined in:
- lib/elastic_search/query_builder.rb,
lib/elastic_search/query_builder/version.rb
Constant Summary collapse
- METHODS =
{ must: %i[query bool must], must_not: %i[query bool must_not], should: %i[query bool should], functions: %i[functions], ids: %i[query terms _id], size: [:size], fields: %i[_source], range: %i[query bool must range], sort: %i[sort], aggs: [:aggs] }.freeze
- VERSION =
'0.6.7'
Instance Attribute Summary collapse
-
#function_score ⇒ Object
Returns the value of attribute function_score.
Instance Method Summary collapse
- #add_to_multisearch(index: {}) ⇒ Object
-
#initialize(opts: {}, mopts: [], client: nil, function_score: false, options: {}) ⇒ QueryBuilder
constructor
A new instance of QueryBuilder.
- #multisearch_results ⇒ Object
- #results ⇒ Object
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(opts: {}, mopts: [], client: nil, function_score: false, options: {}) ⇒ QueryBuilder
Returns a new instance of QueryBuilder.
36 37 38 39 40 41 42 |
# File 'lib/elastic_search/query_builder.rb', line 36 def initialize(opts: {}, mopts: [], client: nil, function_score: false, options: {}) @opts = opts @mopts = mopts @function_score = function_score @client = client @options = end |
Instance Attribute Details
#function_score ⇒ Object
Returns the value of attribute function_score.
7 8 9 |
# File 'lib/elastic_search/query_builder.rb', line 7 def function_score @function_score end |
Instance Method Details
#add_to_multisearch(index: {}) ⇒ Object
60 61 62 63 64 |
# File 'lib/elastic_search/query_builder.rb', line 60 def add_to_multisearch(index: {}) mopts << index mopts << opts.compact @opts = {} end |
#multisearch_results ⇒ Object
54 55 56 57 58 |
# File 'lib/elastic_search/query_builder.rb', line 54 def multisearch_results raise 'client: should be set in order to fetch multisearch_results' unless client client&.msearch(body: mopts)&.dig('responses') end |
#results ⇒ Object
48 49 50 51 52 |
# File 'lib/elastic_search/query_builder.rb', line 48 def results raise 'client: should be set in order to fetch results' unless client client&.search(opts.compact)&.results end |
#to_json(*_args) ⇒ Object
44 45 46 |
# File 'lib/elastic_search/query_builder.rb', line 44 def to_json(*_args) @opts.to_h end |