Search code examples
rubyelasticsearchelasticsearch-api

Get index by name with the ElasticSearch ruby gem


My Model:

class Package < ActiveRecord::Base
  include Elasticsearch::Model
  include Elasticsearch::Model::Callbacks
end

When I ask if the index exists, I get true:

Package.__elasticsearch__.client.indices.exists(index: "packages")
=> true

But when I do:

Package.__elasticsearch__.client.indices.get(index: "packages")

I get this error:

Elasticsearch::Transport::Transport::Errors::BadRequest: [400] No handler found for uri [/packages] and method [GET]

I already have some documents indexed, and I can do a search, so what's wrong with the line above?

ps: here's the doc: http://www.rubydoc.info/gems/elasticsearch-api/Elasticsearch/API/Indices/Actions


Solution

  • It might be the way you've configured your elasticsearch client in your initializer. If you're using the typhoeus adapter, see this discussion: https://github.com/elasticsearch/elasticsearch-rails/issues/316

    Something that might also be helpful is debugging how things are actually indexed / mapped via their marvel plugin http://localhost:9200/_plugin/marvel/sense/index.html?

    GET _cat/indices GET packages/_mapping