{"action":"opened","issue":{"url":"https://api.github.com/repos/elastic/elasticsearch-rails/issues/419","labels_url":"https://api.github.com/repos/elastic/elasticsearch-rails/issues/419/labels{/name}","comments_url":"https://api.github.com/repos/elastic/elasticsearch-rails/issues/419/comments","events_url":"https://api.github.com/repos/elastic/elasticsearch-rails/issues/419/events","html_url":"https://github.com/elastic/elasticsearch-rails/issues/419","id":86292904,"number":419,"title":"search changes after reload","user":{"login":"mustmodify","id":32432,"avatar_url":"https://avatars.githubusercontent.com/u/32432?v=3","gravatar_id":"","url":"https://api.github.com/users/mustmodify","html_url":"https://github.com/mustmodify","followers_url":"https://api.github.com/users/mustmodify/followers","following_url":"https://api.github.com/users/mustmodify/following{/other_user}","gists_url":"https://api.github.com/users/mustmodify/gists{/gist_id}","starred_url":"https://api.github.com/users/mustmodify/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mustmodify/subscriptions","organizations_url":"https://api.github.com/users/mustmodify/orgs","repos_url":"https://api.github.com/users/mustmodify/repos","events_url":"https://api.github.com/users/mustmodify/events{/privacy}","received_events_url":"https://api.github.com/users/mustmodify/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-08T19:01:28Z","updated_at":"2015-06-08T19:01:28Z","closed_at":null,"body":"Very strange behavior that I'm having a difficult time nailing it down. After the app starts up, search works one way and then, mysteriously, adds an index that, as far as I know, isn't set anywhere. I'm wondering if you guys have any thoughts as to why this might be happening.\r\n\r\nStack: Rails 4.2, puma, rbx\r\ngems:\r\nelasticsearch 1.0.9\r\nelasticsearch-api 1.0.9\r\nelasticsearch-transport 1.0.9\r\nelasticsearch-model 0.1.7\r\nelasticsearch-rails 0.1.7\r\n\r\nI hit the searches#show controller via AJAX (or ... actually ... AJAJ but whatever.)\r\n\r\nWhen I restart the server and search for 'auc' I get the expected result for a Person with name \"Kevin Aucain\". From the log entry.\r\n\r\n```\r\nStarted GET \"/search.json?search[term]=auc\" for 127.0.0.1 at 2015-06-08 13\r\nProcessing by SearchesController#show as JSON\r\n  Parameters: {\"search\"=>{\"term\"=>\"auc\"}}\r\n  ... snip ...\r\n  #<Elasticsearch::Model::Multimodel:0x42388> Search (11.1ms) {index: [], type: [], body: {\"query\"=>{\"filtered\"=>{\"query\"=>{\"bool\"=>{\"should\"=>[{\"match_phrase_prefix\"=>{\"_all\"=>\"auc\"}}, {\"query_string\"=>{\"query\"=>\"auc\"}}, {\"fuzzy_like_this\"=>{\"like_text\"=>\"auc\", \"fuzziness\"=>\"AUTO\", \"boost\"=>0.5}}]}}}}}}\r\nCompleted 200 OK in 23ms (Views: 1.1ms | ActiveRecord: 3.7ms | Elasticsearch: 11.1ms)\r\n```\r\n\r\nWhen I reload the page ( which has what effect? Should have none on the search model or controller... ) I stop getting that result. New log entry:\r\n\r\n```\r\nStarted GET \"/search.json?search[term]=auc\" for 127.0.0.1 at 2015-06-08\r\nProcessing by SearchesController#show as JSON\r\n  Parameters: {\"search\"=>{\"term\"=>\"auc\"}}\r\n  ...snip...\r\n  #<Elasticsearch::Model::Multimodel:0x49cf4> Search (4.4ms) {index: [\"organizations\"], type: [\"organization\"], body: {\"query\"=>{\"filtered\"=>{\"query\"=>{\"bool\"=>{\"should\"=>[{\"match_phrase_prefix\"=>{\"_all\"=>\"auc\"}}, {\"query_string\"=>{\"query\"=>\"auc\"}}, {\"fuzzy_like_this\"=>{\"like_text\"=>\"auc\", \"fuzziness\"=>\"AUTO\", \"boost\"=>0.5}}]}}}}}}\r\nCompleted 200 OK in 13ms (Views: 0.2ms | ActiveRecord: 3.1ms | Elasticsearch: 4.4ms)\r\n```\r\n\r\nNotice that the 'index' parameter changed. I have no idea why. I have searched my codebase and can't find any reason for it to have switched.\r\n\r\nSearch model:\r\n```\r\nclass Search < Valuable\r\n  has_value :term\r\n\r\n  def results(options = {page: 1})\r\n    complex_search_a.results\r\n  end\r\n\r\n  def complex_search_a\r\n    query = Elasticsearch::Model.search(\r\n            {\r\n              \"query\"=> {\r\n                \"filtered\"=> {\r\n                  \"query\"=> {\r\n                    \"bool\"=> {\r\n                      \"should\"=> [\r\n                            {\r\n                                \"match_phrase_prefix\"=> {\r\n                                    \"_all\"=> term\r\n                                }\r\n                            },\r\n                            {\r\n                                \"query_string\"=> {\r\n                                    \"query\"=> term\r\n                                }\r\n                            },\r\n                            {\r\n                                \"fuzzy_like_this\"=> {\r\n                                    \"like_text\"=> term,\r\n                                    \"fuzziness\"=> \"AUTO\",\r\n                                    \"boost\"=> 0.5\r\n                                 }\r\n                            }\r\n                      ]\r\n                    }\r\n                  }\r\n                }\r\n              }\r\n            }\r\n    )\r\n  end\r\nend\r\n```\r\n\r\ncontroller:\r\n\r\n```\r\nclass SearchesController < ApplicationController\r\n  def new\r\n    @search = Search.new\r\n  end\r\n\r\n  def show\r\n    @search = Search.new( local_params )\r\n    @results = @search.results\r\n\r\n    respond_to do |format|\r\n      format.html { render :action => 'show' }\r\n      format.json { render :json => {results: @results} }\r\n    end\r\n  end\r\n```\r\n\r\nand the models:\r\n\r\n```\r\nclass Organization < ActiveRecord::Base\r\n  include Elasticsearch::Model\r\n  include Elasticsearch::Model::Callbacks\r\n\r\n  def as_indexed_json(stuff= nil)\r\n    {\r\n      name: self.name,\r\n      dba: self.dba,\r\n      uri: \"/organizations/#{self.id}\",\r\n      description: '',\r\n    }\r\n  end\r\nend\r\n```\r\n\r\n```\r\nclass Person < ActiveRecord::Base\r\n  include Elasticsearch::Model\r\n  include Elasticsearch::Model::Callbacks\r\n\r\n  def as_indexed_json(stuff= nil)\r\n    {\r\n      name: self.name,\r\n      uri: \"/people/#{self.id}\",\r\n      description: self.organization.try(&:name),\r\n    }\r\n  end\r\n```"}}