Skip to content

Commit 16ef393

Browse files
committed
[MODEL] Fixed the completion example for ActiveRecord for Elasticsearch 5
1 parent ed0ee82 commit 16ef393

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

elasticsearch-model/examples/activerecord_mapping_completion.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ class Article < ActiveRecord::Base
1818
include Elasticsearch::Model::Callbacks
1919

2020
mapping do
21-
indexes :title
22-
indexes :title_suggest, type: 'completion', payloads: true
21+
indexes :title, type: 'text'
22+
indexes :title_suggest, type: 'completion'
23+
indexes :url, type: 'keyword'
2324
end
2425

2526
def as_indexed_json(options={})
2627
as_json.merge \
27-
title_suggest: {
28-
input: title,
29-
output: title,
30-
payload: { url: "/articles/#{id}" }
31-
}
28+
title_suggest: { input: title },
29+
url: "/articles/#{id}"
3230
end
3331
end
3432

@@ -63,7 +61,7 @@ def as_indexed_json(options={})
6361
};
6462

6563
puts "Article suggest:".ansi(:bold),
66-
response_2['articles'].first['options'].map { |d| "#{d['text']} -> #{d['payload']['url']}" }.
64+
response_2['articles'].first['options'].map { |d| "#{d['text']} -> #{d['_source']['url']}" }.
6765
inspect.ansi(:bold, :green)
6866

6967
require 'pry'; binding.pry;

0 commit comments

Comments
 (0)