Skip to content

Commit

Permalink
update conditional logic for status code, dynamic_templates key
Browse files Browse the repository at this point in the history
  • Loading branch information
wkdewey committed Oct 25, 2022
1 parent 0ec2665 commit 7b90a09
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/datura/elasticsearch/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ def get_schema_mapping
end

regex_pieces = []
doc["dynamic_templates"].each do |template|
mapping = template.map { |k,v| v["match"] }.first
# dynamic fields are listed like *_k and will need
# to be converted to ^.*_k$, then combined into a mega-regex
es_match = mapping.sub("*", ".*")
regex_pieces << es_match
if doc["dynamic_templates"]
doc["dynamic_templates"].each do |template|
mapping = template.map { |k,v| v["match"] }.first
# dynamic fields are listed like *_k and will need
# to be converted to ^.*_k$, then combined into a mega-regex
es_match = mapping.sub("*", ".*")
regex_pieces << es_match
end
end
if !regex_pieces.empty?
regex_joined = regex_pieces.join("|")
Expand Down Expand Up @@ -231,7 +233,7 @@ def self.clear_index(options)
data = self.build_clear_data(options)
auth_header = Datura::Helpers.construct_auth_header(options)
RestClient.post(url, data.to_json, auth_header.merge({content_type: :json })) { |res, req, result|
if result.code == "200"
if result.code == "200" || result.code == "201"
puts res
else
raise "#{result.code} error when clearing index: #{res}"
Expand Down

0 comments on commit 7b90a09

Please sign in to comment.