Skip to content

Commit d3bedfb

Browse files
committed
Feature: Support for remote Elasticsearch clusters
1 parent 1d6e74c commit d3bedfb

File tree

3 files changed

+71
-5
lines changed

3 files changed

+71
-5
lines changed

app/services/elasticsearch_query_service.rb

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,23 @@ def initialize(data_query, data_source, options, source_options, current_user)
1313
end
1414

1515
def self.connection options
16+
17+
scheme = options.dig('scheme', 'value')
18+
host = options.dig('host', 'value')
19+
port = options.dig('port', 'value')
20+
username = options.dig('username', 'value')
21+
password = options.dig('password', 'value')
22+
23+
unless username.blank? || password.blank?
24+
url = "#{scheme}://#{username}:#{password}@#{host}:#{port}"
25+
else
26+
url = "#{scheme}://#{host}:#{port}"
27+
end
28+
1629
client = Elasticsearch::Client.new(
17-
url: "#{options.dig('host', 'value')}:#{options.dig('port', 'value')}",
30+
url: url,
1831
retry_on_failure: 5,
19-
request_timeout: 30,
32+
request_timeout: 15,
2033
adapter: :typhoeus
2134
)
2235

@@ -71,10 +84,23 @@ def process
7184

7285
private
7386
def create_connection
87+
88+
scheme = source_options['scheme']
89+
host = source_options['host']
90+
port = source_options['port']
91+
username = source_options['username']
92+
password = source_options['password']
93+
94+
unless username.blank? || password.blank?
95+
url = "#{scheme}://#{username}:#{password}@#{host}:#{port}"
96+
else
97+
url = "#{scheme}://#{host}:#{port}"
98+
end
99+
74100
connection = Elasticsearch::Client.new(
75-
url: "#{source_options['host']}:#{source_options['port']}",
101+
url: url,
76102
retry_on_failure: 5,
77-
request_timeout: 30,
103+
request_timeout: 15,
78104
adapter: :typhoeus
79105
)
80106

frontend/src/Editor/DataSourceManager/DefaultOptions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const defaultOptions = {
3030
},
3131

3232
elasticsearch: {
33+
scheme: { value: 'https' },
3334
host: { value: 'localhost' },
3435
port: { value: 9200 },
3536
username: { value: '' },

frontend/src/Editor/DataSourceManager/SourceComponents/Elasticsearch.jsx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
import React from 'react';
2+
import SelectSearch, { fuzzySearch } from 'react-select-search';
23

34
export const Elasticsearch = ({
45
optionchanged, options
56
}) => {
67
return (
78
<div>
89
<div className="row">
9-
<div className="col-md-9">
10+
<div className="col-md-2 mb-2">
11+
<label className="form-label">
12+
Scheme
13+
</label>
14+
<SelectSearch
15+
options={[
16+
{name: 'http', value: 'http'},
17+
{name: 'https', value: 'https'}
18+
]}
19+
value={options.scheme.value}
20+
search={true}
21+
onChange={(value) => {
22+
optionchanged('scheme', value);
23+
}}
24+
filterOptions={fuzzySearch}
25+
placeholder="Select.."
26+
/>
27+
</div>
28+
<div className="col-md-7">
1029
<label className="form-label">Host</label>
1130
<input
1231
type="text"
@@ -24,6 +43,26 @@ export const Elasticsearch = ({
2443
value={options.port.value}
2544
/>
2645
</div>
46+
<div className="row mt-3">
47+
<div className="col-md-6">
48+
<label className="form-label">Username</label>
49+
<input
50+
type="text"
51+
className="form-control"
52+
onChange={(e) => optionchanged('username', e.target.value)}
53+
value={options.username.value}
54+
/>
55+
</div>
56+
<div className="col-md-6">
57+
<label className="form-label">Password</label>
58+
<input
59+
type="text"
60+
className="form-control"
61+
onChange={(e) => optionchanged('password', e.target.value)}
62+
value={options.password.value}
63+
/>
64+
</div>
65+
</div>
2766
</div>
2867
</div>
2968
);

0 commit comments

Comments
 (0)