elastic / elasticsearch-rails

Elasticsearch integrations for ActiveModel/Record and Ruby on Rails
Apache License 2.0
3.07k stars 797 forks source link

[404] {"error":"IndexMissingException[[Index_Key] missing]","status":404} #396

Closed vfa-dunghn closed 5 years ago

vfa-dunghn commented 9 years ago

Hi friends. I have a model

require 'elasticsearch/model'

class Club
  include Mongoid::Document
  include Mongoid::Timestamps
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks
  include Mongoid::Attributes::Dynamic

  index_name "club-ygo"

  settings index: { number_of_shards: 1 } do
    mappings dynamic: 'false' do
      indexes :id, index: :not_analyzed
      indexes :name, index: :not_analyzed
    end
  end

  def as_indexed_json(options={})
    as_json(
      only: [:id, :name,  :address, :display, :loc, :country, :city, :updated_at],
      methods: [:search_keys]
    )
  end
Club.search('aero')
karmi commented 9 years ago

Can you model your question with an executable example like this one: https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-model/examples/mongoid_article.rb so I can just run it and see?

iamanujvrma commented 8 years ago

Hi @vfa-dunghn , Have you created an index for your model Club. If not, this can be a reason for your error. Before searching, you must index your documents by running the following command for each document in your Club model. Club.each { |club| club.__elasticsearch__.index_document! } Or you can index all documents of your model by executing these two commands:

  1. Club.__elasticsearch__.create_index!
  2. Club.import After indexing your documents you can search them by executing: Club.search('aero')
estolfo commented 5 years ago

Hi @vfa-dunghn can I close this?

estolfo commented 5 years ago

Closing issue as there hasn't been activity on it since 2016.