5

I already did Comment.import and it returned 0, which means there were no errors during the import process.

I already did Comment.__elasticsearch__.refresh_index!

This is the model I'm using:

require "datamapper_adapter"

class Comment
  include DataMapper::Resource

  include Elasticsearch::Model

  property :id, Serial
  property :email, String
  property :author, String
  property :description, String
  property :created_at, DateTime

  belongs_to :picture

  validates_presence_of :email, :author, :description

  settings index: { number_of_shards: 1 } do
    mappings dynamic: 'false' do
      indexes :id, analyzer: 'english', index_options: 'offsets'
      indexes :author, analyzer: 'english', index_options: 'offsets'
      indexes :description, analyzer: 'english', index_options: 'offsets'
    end
  end

  def as_indexed_json(options={})
    as_json.except("picture_id", "created_at", "email", "_persistence_state", "_repository", "_id")
  end
end

And still all my queries to the elasticsearch return an empty array as hits.

curl -XPOST 'http://localhost:9200/comments/comment/_search?pretty
{
    "took" : 35,
    "timed_out" : false,
    "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
    "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

I have data in my DB but I have no idea why it never gets filtered. Any ideas why this is happening? This is driving me nuts

No matter what I do, hits is ALWAYS empty

3
  • Any chance to increase the DEBUG level to get more insights on what's going on during the import? Commented Aug 17, 2015 at 16:36
  • Download elasticsearch head (mobz.github.io/elasticsearch-head), and connect to your ES instance. Does it contain the data you expect? Commented Aug 18, 2015 at 21:16
  • A quick way to see if there is data in the index is curl -XPOST 'http://localhost:9200/comments/comment/_count' Commented Aug 18, 2015 at 21:33

1 Answer 1

1
+100

could you try to add type:string to indexes :description and indexes :author

I also remember I had problem with as_json, for older rails versions it will include root attribute. Try to set it to false, you can do this globally or in the as_json( root: false )

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.