Class: Noiseless::Adapter
Constant Summary
collapse
- GEO_FILTER_KEYS =
%i[geo_distance geo_bounding_box geo_polygon geo_shape].freeze
- RANGE_OPERATORS =
%i[gte lte gt lt].freeze
- FIELD_BASED_AGG_TYPES =
Aggregation types that require a field (or script) to execute.
%i[
terms rare_terms significant_terms missing
avg sum min max cardinality value_count stats extended_stats
percentiles percentile_ranks histogram date_histogram
geohash_grid geotile_grid geo_distance
].freeze
Instance Method Summary
collapse
-
#async_context? ⇒ Boolean
-
#bulk(actions) ⇒ Object
-
#create_index(index_name) ⇒ Object
-
#delete_document(index:, id:) ⇒ Object
-
#delete_index(index_name) ⇒ Object
-
#document_exists?(index:, id:) ⇒ Boolean
-
#index_document(index:, id:, document:) ⇒ Object
-
#index_exists?(index_name) ⇒ Boolean
-
#initialize(hosts: [], **connection_params) ⇒ Adapter
constructor
A new instance of Adapter.
-
#refresh_index(index_name) ⇒ Object
-
#search(ast_node, model_class: nil, response_type: nil) ⇒ Object
Convert AST to Hash/JSON before execution.
-
#search_raw(query_body, indexes: []) ⇒ Object
Raw search method for backward compatibility.
-
#update_document(index:, id:, changes:) ⇒ Object
#adapter_capabilities, #adapter_info, #build_execution_plan, #compatibility_matrix, #detect_execution_module, #engine_name, #explain_query, #profile_query
#instrument
Constructor Details
#initialize(hosts: [], **connection_params) ⇒ Adapter
Returns a new instance of Adapter.
23
24
25
26
27
|
# File 'lib/noiseless/adapter.rb', line 23
def initialize(hosts: [], **connection_params)
@hosts = hosts
@connection_params = connection_params.dup
@connection_params.delete(:async)
end
|
Instance Method Details
#async_context? ⇒ Boolean
29
30
31
|
# File 'lib/noiseless/adapter.rb', line 29
def async_context?
true
end
|
#bulk(actions) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/noiseless/adapter.rb', line 51
def bulk(actions, **)
Async do
instrument(:bulk, actions_count: actions.size) do
execute_bulk(actions, **)
end
end
end
|
#create_index(index_name) ⇒ Object
59
60
61
62
63
64
65
|
# File 'lib/noiseless/adapter.rb', line 59
def create_index(index_name, **)
Async do
instrument(:create_index, index: index_name) do
execute_create_index(index_name, **)
end
end
end
|
#delete_document(index:, id:) ⇒ Object
105
106
107
108
109
110
111
|
# File 'lib/noiseless/adapter.rb', line 105
def delete_document(index:, id:, **)
Async do
instrument(:delete_document, index: index, id: id) do
execute_delete_document(index, id, **)
end
end
end
|
#delete_index(index_name) ⇒ Object
67
68
69
70
71
72
73
|
# File 'lib/noiseless/adapter.rb', line 67
def delete_index(index_name, **)
Async do
instrument(:delete_index, index: index_name) do
execute_delete_index(index_name, **)
end
end
end
|
#document_exists?(index:, id:) ⇒ Boolean
113
114
115
116
117
|
# File 'lib/noiseless/adapter.rb', line 113
def document_exists?(index:, id:)
Async do
execute_document_exists?(index, id)
end
end
|
#index_document(index:, id:, document:) ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/noiseless/adapter.rb', line 89
def index_document(index:, id:, document:, **)
Async do
instrument(:index_document, index: index, id: id) do
execute_index_document(index, id, document, **)
end
end
end
|
#index_exists?(index_name) ⇒ Boolean
83
84
85
86
87
|
# File 'lib/noiseless/adapter.rb', line 83
def index_exists?(index_name)
Async do
execute_index_exists?(index_name)
end
end
|
#refresh_index(index_name) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/noiseless/adapter.rb', line 75
def refresh_index(index_name)
Async do
instrument(:refresh_index, index: index_name) do
execute_refresh_index(index_name)
end
end
end
|
#search(ast_node, model_class: nil, response_type: nil) ⇒ Object
Convert AST to Hash/JSON before execution
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/noiseless/adapter.rb', line 34
def search(ast_node, model_class: nil, response_type: nil, **)
query_hash = ast_to_hash(ast_node)
Async do
raw_response = instrument(:search, indexes: ast_node.indexes, query: query_hash) do
execute_search(query_hash, indexes: ast_node.indexes, **)
end
ResponseFactory.create(
raw_response,
model_class: model_class,
response_type: response_type,
query_hash: query_hash
)
end
end
|
#search_raw(query_body, indexes: []) ⇒ Object
Raw search method for backward compatibility
120
121
122
123
124
125
126
|
# File 'lib/noiseless/adapter.rb', line 120
def search_raw(query_body, indexes: [], **)
Async do
instrument(:search, indexes: indexes, query: query_body) do
execute_search(query_body, indexes: indexes, **)
end
end
end
|
#update_document(index:, id:, changes:) ⇒ Object
97
98
99
100
101
102
103
|
# File 'lib/noiseless/adapter.rb', line 97
def update_document(index:, id:, changes:, **)
Async do
instrument(:update_document, index: index, id: id, changes_count: changes.size) do
execute_update_document(index, id, changes, **)
end
end
end
|