Skip to content
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

Rails template 03-expert.rb fails #521

Closed
lgs opened this issue Jan 16, 2016 · 11 comments
Closed

Rails template 03-expert.rb fails #521

lgs opened this issue Jan 16, 2016 · 11 comments
Labels

Comments

@lgs
Copy link

lgs commented Jan 16, 2016

running rails new searchapp --skip --skip-bundle --template https://raw.github.com/elasticsearch/elasticsearch-rails/master/elasticsearch-rails/lib/rails/templates/03-expert.rb

currently result in the following error: ActionView::Template::Error ... failed to parse search source. unknown search element [facets] ...

see the full log here:

Started GET "/" for 127.0.0.1 at 2016-01-16 22:12:23 +0100
  ActiveRecord::SchemaMigration Load (0.1ms)  SELECT "schema_migrations".* FROM "schema_migrations"
Processing by SearchController#index as HTML
  Article Search (8.2ms) {index: "searchapp_application_development", type: "article", body: {query: {match_all: {}}, highlight: {pre_tags: [""], post_tags: [""], fields: {title: {number_of_fragments: 0}, abstract: {number_of_fragments: 0}, content: {fragment_size: 50}}}, filter: {}, facets: {categories: {terms: {field: "categories"}, facet_filter: {}}, authors: {terms: {field: "authors.full_name.raw"}, facet_filter: {}}, published: {date_histogram: {field: "published_on", interval: "week"}, facet_filter: {}}}, sort: {published_on: "desc"}}, size: 25, from: 0}
  Rendered search/index.html.erb within layouts/application (20.9ms)
Completed 500 Internal Server Error in 61ms (ActiveRecord: 0.2ms | Elasticsearch: 8.2ms)

ActionView::Template::Error ([400] {"error":{"root_cause":[{"type":"search_parse_exception","reason":"failed to parse search source. unknown search element [facets]","line":1,"col":239}],"type":"search_phase_execution_exception","reason":"all shards failed","phase":"query_fetch","grouped":true,"failed_shards":[{"shard":0,"index":"searchapp_application_development","node":"Jsi8lCo4Se2c-xcdIQQ_yA","reason":{"type":"search_parse_exception","reason":"failed to parse search source. unknown search element [facets]","line":1,"col":239}}]},"status":400}):
    24:       
    25: 
    26:       
27:

Displaying <%= (params[:page] || 1).to_i.ordinalize %> page with <%= @articles.size %> articles 28: of total <%= @articles.total %>

29: 30: app/views/search/index.html.erb:27:in `block in _app_views_search_index_html_erb__4565196024839181062_47154999019880' app/views/search/index.html.erb:4:in `_app_views_search_index_html_erb__4565196024839181062_47154999019880'

here it is the stack version:

$ curl localhost:9200 
{
  "name" : "Stinger",
  "cluster_name" : "elasticsearch",
  "version" : {
    "number" : "2.1.1",
    "build_hash" : "40e2c53a6b6c2972b3d13846e450e66f4375bd71",
    "build_timestamp" : "2015-12-15T13:05:55Z",
    "build_snapshot" : false,
    "lucene_version" : "5.3.1"
  },
  "tagline" : "You Know, for Search"
}

$ rails -v
Rails 4.2.5

$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]

$ java -version
java version "1.8.0_66"
Java(TM) SE Runtime Environment (build 1.8.0_66-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.66-b17, mixed mode)

$ uname -a
Linux basenode 4.2.0-23-generic #28-Ubuntu SMP Sun Dec 27 17:47:31 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
@karmi
Copy link
Contributor

karmi commented Jan 17, 2016

Thanks for the report!, I'm aware of it, and will focus on fixing it in the next weeks, as well as improving the Rails integration in general. The 04-dsl.rb template uses aggregations, so it should work on ES 2.x.

@karmi karmi added the bug label Jan 17, 2016
@karmi karmi closed this as completed in 77ce500 Jan 21, 2016
@lgs
Copy link
Author

lgs commented Jan 22, 2016

It works fine, ... anyway it seems many data are missing. If I remember well, previously it had many articles and different authors as demo data.

Now it looks like just one see screenshot here

@karmi
Copy link
Contributor

karmi commented Jan 22, 2016

So, either delete the app and run the templates again, or re-import the data? If you access the home page at http://localhost:3000, it should list 929 articles, is it the case?

@lgs
Copy link
Author

lgs commented Jan 22, 2016

... just what I did: rm -rf searchapp then run templates again from 1 to 3 and I got what you see in the previous sceenshot.

Also trying re-import I got the following:

$ rake elasticsearch:import:all
[IMPORT] Loading models from: /home/lsoave/test/searchapp/app/models
rake aborted!
NameError: uninitialized constant Article::Searchable
/home/lsoave/test/searchapp/app/models/article.rb:9:in `'
/home/lsoave/test/searchapp/app/models/article.rb:1:in `'
NameError: uninitialized constant Article
Tasks: TOP => elasticsearch:import:all
(See full trace by running task with --trace)

@karmi
Copy link
Contributor

karmi commented Jan 22, 2016

Yeah, that's expected :) You have to load the Rails' environment as well:

bundle exec rake environment elasticsearch:import:all FORCE=y

@lgs
Copy link
Author

lgs commented Jan 22, 2016

ok I got it ...

$ bundle exec rake environment elasticsearch:import:all FORCE=y
[IMPORT] Loading models from: /home/lsoave/test/searchapp/app/models
[IMPORT] Processing model: Article...
[IMPORT] Done

... but sadly I get the same "one article" app.

I also notice two things:

 1. at the end of template 2 apply, I got all the 1K articles & the app fully working
 2. during template 3 apply, I got redis error (Redis::CannotConnectError)

Is Redis a pre-requisite now ? Follow the template 03-expert.rb log:

Reading articles from gzipped YAML...
 (0.1ms)  begin transaction
SQL (0.3ms)  INSERT INTO "articles" ("title", "abstract", "content", "url", "shares", "published_on", "created_at", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?)  [["title", "How Y’all, Youse and You Guys Talk"], ["abstract", "What does the way you speak say about where you’re from? Answer the questions to see your personal dialect map."], ["content", ""]..."], ["url", "http://www.nytimes.com/interactive/2013/12/20/sunday-review/dialect-quiz-map.html"], ["shares", 1], ["published_on", "2013-12-20"], ["created_at", "2016-01-22 15:24:44.751902"], ["updated_at", "2016-01-22 15:24:44.751902"]]
 (70.0ms)  commit transaction
rake aborted!
Redis::CannotConnectError: Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)
/home/lsoave/test/searchapp/app/models/concerns/searchable.rb:51:in `block (2 levels) in '
/home/lsoave/test/searchapp/db/seeds.rb:38:in `block in '
/home/lsoave/test/searchapp/db/seeds.rb:37:in `each'
/home/lsoave/test/searchapp/db/seeds.rb:37:in `'
Errno::ECONNREFUSED: Connection refused - connect(2) for 127.0.0.1:6379
/home/lsoave/test/searchapp/app/models/concerns/searchable.rb:51:in `block (2 levels) in '
/home/lsoave/test/searchapp/db/seeds.rb:38:in `block in '
/home/lsoave/test/searchapp/db/seeds.rb:37:in `each'
/home/lsoave/test/searchapp/db/seeds.rb:37:in `'
IO::EINPROGRESSWaitWritable: Operation now in progress - connect(2) would block
/home/lsoave/test/searchapp/app/models/concerns/searchable.rb:51:in `block (2 levels) in '
/home/lsoave/test/searchapp/db/seeds.rb:38:in `block in '
/home/lsoave/test/searchapp/db/seeds.rb:37:in `each'
/home/lsoave/test/searchapp/db/seeds.rb:37:in `'
Tasks: TOP => db:setup => db:seed
(See full trace by running task with --trace)

@lgs
Copy link
Author

lgs commented Jan 22, 2016

Ok that's it !

Redis server must be up and running, in order to Sidekiq worker being able to update the index: see room "Add Sidekiq indexer" @line 181 in the new 03-expert template

Then, having Redis Server Up & Running is a prerequisite.

on Ubuntu 15.10 :

$ sudo service redis-server status
● redis-server.service - Advanced key-value store
   Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
   Active: active (running) since ven 2016-01-22 17:37:51 CET; 13min ago
 Main PID: 6460 (redis-server)
   Memory: 6.2M
      CPU: 1.380s
   CGroup: /system.slice/redis-server.service
           └─6460 /usr/bin/redis-server 127.0.0.1:6379
gen 22 17:37:51 basenode systemd[1]: Starting Advanced key-value store...
gen 22 17:37:51 basenode systemd[1]: Started Advanced key-value store.

@lgs
Copy link
Author

lgs commented Jan 22, 2016

... and I would also like to say thank you @karmi, for the great & useful 77ce500 commit, as well as for the rest of his (long time) work with ruby/rails/elasticsearch !!!

@karmi
Copy link
Contributor

karmi commented Jan 22, 2016

Thank you, Luca! I appreciate it a lot. And yes, updating the application has been something I've been postponing for far too long, I'm glad I've finally managed to do it.

You're correct about Redis having to be up -- I think it makes sense to put some logic into the template to raise a warning when it cannot connect to Redis, to prevent a confusing scenario like you've hit.

@karmi
Copy link
Contributor

karmi commented Jan 22, 2016

I've added a check for Redis availability into the template in the attached commit. Thanks for raising the issue!

@lgs
Copy link
Author

lgs commented Jan 22, 2016

489ab24 👍 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants