Description
@karmi thank you for all of your incredible work on Elastic. We happily converted our repositories to Elastic a few months ago and are giving a talk in our community about why we did so.
I'm eager to add in autocomplete. I read over your excellent completion suggester example here.
Here is my (abbreviated) code:
class Page
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
settings index: { number_of_shards: 1 } do
mappings dynamic: 'false' do
indexes :title, analyzer: 'english', index_options: 'offsets'
indexes :title_suggest, type: 'completion', payloads: true
indexes :description, analyzer: 'english'
indexes :site_id, analyzer: 'english'
end
end
def as_indexed_json(options={})
as_json.merge \
title_suggest: {
input: title,
output: title,
payload: { url: "/pages/#{id}" }
}
end
end
For importing, I tried both:
Page.__elasticsearch__.client.indices.delete index: Page.index_name rescue nil
Page.__elasticsearch__.client.indices.create \
index: Page.index_name,
body: { settings: Page.settings.to_hash, mappings: Page.mappings.to_hash }
Page.import query: -> { where(status_id: 100, indexable: true, class_name: [nil, '']) }, batch_size: 100
and
Page.__elasticsearch__.create_index! force: true
Page.__elasticsearch__.refresh_index!
Page.import query: -> { where(status_id: 100, indexable: true, class_name: [nil, '']) }, batch_size: 100}
Unfortunately, I'm consistently getting:
Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Mapping definition for [title_suggest] has unsupported parameters: [payloads : true]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [page]: Mapping definition for [title_suggest] has unsupported parameters: [payloads : true]","caused_by":{"type":"mapper_parsing_exception","reason":"Mapping definition for [title_suggest] has unsupported parameters: [payloads : true]"}},"status":400}
I'm using elasticsearch-5.1.1 with elasticsearch-model and elasticsearch-rails gems installed on Rails 4.2.7. Is it possible that payload was deprecated? I appreciate any guidance on how to map the Page.title to the title_suggest field so that I can call:
Elasticsearch::Model.client.suggest(index: "pages",
body: {
suggestion: {
text: params[:q].to_s,
completion: {
field: 'title_suggest'
}
}
})
Thanks!