-
Notifications
You must be signed in to change notification settings - Fork 801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating multiple mappings for one model/index #429
Comments
Hmm, not sure about nesting the completion type in multi field, can you try the following example: require 'ansi'
require 'active_record'
require 'elasticsearch/model'
ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
ActiveRecord::Base.establish_connection( adapter: 'sqlite3', database: ":memory:" )
ActiveRecord::Schema.define(version: 1) do
create_table :articles do |t|
t.string :title
t.date :published_at
t.timestamps
end
end
class Article < ActiveRecord::Base
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
mapping do
indexes :title
indexes :title_suggest, type: 'completion', payloads: true
end
def as_indexed_json(options={})
as_json.merge \
title_suggest: {
input: title,
output: title,
payload: { url: "/articles/#{id}" }
}
end
end
Article.__elasticsearch__.client = Elasticsearch::Client.new log: true
# Create index
Article.__elasticsearch__.create_index! force: true
# Store data
Article.delete_all
Article.create title: 'Foo'
Article.create title: 'Bar'
Article.create title: 'Foo Foo'
Article.__elasticsearch__.refresh_index!
# Search and suggest
response_1 = Article.search 'foo';
puts "Article search:".ansi(:bold), response_1.to_a.map(&:title).inspect.ansi(:bold, :yellow)
response_2 = Article.__elasticsearch__.client.suggest \
index: Article.index_name,
body: {
articles: {
text: 'foo',
completion: { field: 'title_suggest', size: 25 }
}
};
puts "Article suggest:".ansi(:bold), response_2['articles'].inspect.ansi(:bold, :green)
require 'pry'; binding.pry; |
karmi
added a commit
that referenced
this issue
Jun 20, 2015
@karmi sorry for prolonged response, I will test later today and close issue once resolved. Thanks so much for your support! |
@karmi Awesome. That worked, thank you for your support! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want to create two mappings, one for conventional search and the other using a Completion Suggestor. According to elasticsearch the latter requires a separate mapping - https://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html
I have the following code:
But get this error when indexing my model:
Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":"MapperParsingException[mapping [spree_product]]; nested: MapperParsingException[Root type mapping not empty after parsing! Remaining fields: [_suggest : {search_analyzer=whitespace_analyzer, index_analyzer=simple}]]; ","status":400}
/usr/local/bundle/gems/elasticsearch-transport-1.0.12/lib/elasticsearch/transport/transport/base.rb:135:in
__raise_transport_error' /usr/local/bundle/gems/elasticsearch-transport-1.0.12/lib/elasticsearch/transport/transport/base.rb:227:in
perform_request'/usr/local/bundle/gems/elasticsearch-transport-1.0.12/lib/elasticsearch/transport/transport/http/faraday.rb:20:in
perform_request' /usr/local/bundle/gems/elasticsearch-transport-1.0.12/lib/elasticsearch/transport/client.rb:119:in
perform_request'/usr/local/bundle/gems/elasticsearch-api-1.0.12/lib/elasticsearch/api/namespace/common.rb:21:in
perform_request' /usr/local/bundle/gems/elasticsearch-api-1.0.12/lib/elasticsearch/api/actions/indices/create.rb:77:in
create'/tmp/spree_elasticsearch/lib/tasks/load_products.rake:5:in `block (2 levels) in <top (required)>'
Tasks: TOP => spree_elasticsearch:load_products
(See full trace by running task with --trace)
The text was updated successfully, but these errors were encountered: