Skip to content
Permalink
Browse files

Made type optional for custom mapping for Elasticsearch 6 - #1260

  • Loading branch information...
ankane committed May 7, 2019
1 parent 33ee919 commit 5d8cdd0d1a46c89a8359616aa8a183244f4659aa
Showing with 19 additions and 11 deletions.
  1. +1 −0 CHANGELOG.md
  2. +2 −4 README.md
  3. +16 −6 lib/searchkick/index_options.rb
  4. +0 −1 test/models/store.rb
@@ -1,5 +1,6 @@
## 4.0.1 [unreleased]

- Made type optional for custom mapping for Elasticsearch 6
- Fixed error when suggestions empty
- Fixed `models` option with inheritance

@@ -1396,10 +1396,8 @@ Create a custom mapping:
```ruby
class Product < ApplicationRecord
searchkick mappings: {
product: {
properties: {
name: {type: "keyword"}
}
properties: {
name: {type: "keyword"}
}
}
end
@@ -5,12 +5,24 @@ def index_options
language = options[:language]
language = language.call if language.respond_to?(:call)

below62 = Searchkick.server_below?("6.2.0")
below70 = Searchkick.server_below?("7.0.0")

if below70
index_type = options[:_type]
index_type = index_type.call if index_type.respond_to?(:call)
end

custom_mapping = (options[:mapping] || {}).symbolize_keys
if below70 && custom_mapping.any? && custom_mapping.key?(:properties)
# add type
custom_mapping = {index_type.to_sym => custom_mapping}
end

if options[:mappings] && !options[:merge_mappings]
settings = options[:settings] || {}
mappings = options[:mappings]
mappings = custom_mapping
else
below62 = Searchkick.server_below?("6.2.0")
below70 = Searchkick.server_below?("7.0.0")

default_type = "text"
default_analyzer = :searchkick_index
@@ -411,12 +423,10 @@ def index_options
}

if below70
index_type = options[:_type]
index_type = index_type.call if index_type.respond_to?(:call)
mappings = {index_type => mappings}
end

mappings = mappings.symbolize_keys.deep_merge((options[:mappings] || {}).symbolize_keys)
mappings = mappings.symbolize_keys.deep_merge(custom_mapping)
end

{
@@ -4,7 +4,6 @@ class Store
name: {type: "keyword"}
}
}
mappings = {store: mappings} if Searchkick.server_below?("7.0.0")

searchkick \
routing: true,

0 comments on commit 5d8cdd0

Please sign in to comment.
You can’t perform that action at this time.