lib/searchkick/index.rb in searchkick-1.0.1 vs lib/searchkick/index.rb in searchkick-1.0.2
- old
+ new
@@ -25,10 +25,14 @@
def alias_exists?
client.indices.exists_alias name: name
end
+ def mapping
+ client.indices.get_mapping index: name
+ end
+
def swap(new_name)
old_indices =
begin
client.indices.get_alias(name: name).keys
rescue Elasticsearch::Transport::Transport::Errors::NotFound
@@ -60,15 +64,19 @@
end
end
def import(records)
records.group_by { |r| document_type(r) }.each do |type, batch|
- client.bulk(
- index: name,
- type: type,
- body: batch.map { |r| {index: {_id: search_id(r), data: search_data(r)}} }
- )
+ response =
+ client.bulk(
+ index: name,
+ type: type,
+ body: batch.map { |r| {index: {_id: search_id(r), data: search_data(r)}} }
+ )
+ if response["errors"]
+ raise Searchkick::ImportError, response["items"].first["index"]["error"]
+ end
end
end
def retrieve(record)
client.get(
@@ -199,10 +207,12 @@
end
end
def index_options
options = @options
+ language = options[:language]
+ language = language.call if language.respond_to?(:call)
if options[:mappings] && !options[:merge_mappings]
settings = options[:settings] || {}
mappings = options[:mappings]
else
@@ -315,11 +325,11 @@
max_gram: 50
},
searchkick_stemmer: {
# use stemmer if language is lowercase, snowball otherwise
# TODO deprecate language option in favor of stemmer
- type: options[:language] == options[:language].to_s.downcase ? "stemmer" : "snowball",
- language: options[:language] || "English"
+ type: language == language.to_s.downcase ? "stemmer" : "snowball",
+ language: language || "English"
}
},
char_filter: {
# https://www.elastic.co/guide/en/elasticsearch/guide/current/custom-analyzers.html
# &_to_and