Coder Social home page Coder Social logo

Comments (4)

karmi avatar karmi commented on June 17, 2024

Hi @anthonator, apologies, this has slipped me. When you say:

When I save a model the data never hits Elasticsearch.

Can you please configure the client with log: true and check what is being sent to ES and when?

Notice the "concern" module pattern is covered by the examples and the Rails demo application.

from elasticsearch-rails.

karmi avatar karmi commented on June 17, 2024

Hi, closing this, please ping me if you need more help.

from elasticsearch-rails.

halloffame avatar halloffame commented on June 17, 2024

I'm having a similar issue. My search concern is structured pretty much the same as anthonator. Here are my logs.

# When I index it explicitly it works as expected and passes ES the right data.
2.0.0-p451 :004 > Department.first.__elasticsearch__.update_document
2014-05-22 15:31:18 -0700: PUT http://localhost:9200/directory/department/53603b2e59397c60d7000001 [status:200, request:0.008s, query:n/a]
2014-05-22 15:31:18 -0700: > {"title":"Yoshi Pit Crew","location":"yoshi island"}
2014-05-22 15:31:18 -0700: < {"_index":"directory","_type":"department","_id":"53603b2e59397c60d7000001","_version":16,"created":false}

# But when I update the model, it is not passing ES the same data.
2.0.0-p451 :001 > Department.first.update_attribute :location, 'Rainbow Road'
2014-05-22 15:32:24 -0700: POST http://localhost:9200/directory/department/53603b2e59397c60d7000001/_update [status:200, request:0.066s, query:n/a]
2014-05-22 15:32:24 -0700: > {"doc":{}}
2014-05-22 15:32:24 -0700: < {"_index":"directory","_type":"department","_id":"53603b2e59397c60d7000001","_version":17}

When I replace

include Elasticsearch::Model::Callbacks

with

after_create  { __elasticsearch__.index_document  }
after_update  { __elasticsearch__.update_document }
after_destroy { __elasticsearch__.delete_document }

it still does the same thing. Any ideas what may be going on?

from elasticsearch-rails.

halloffame avatar halloffame commented on June 17, 2024

Ok, I think I figured out what is going on. https://github.com/elasticsearch/elasticsearch-rails/blob/master/elasticsearch-model/lib/elasticsearch/model/indexing.rb#L336

The update_model method first checks to see if any attributes have changed. If it finds any it will only try to update those into elasticsearch. That's where that {"doc":{}} in the logs above is coming from.

The problem for me as well as @anthonator is that what as_indexed_json returns doesn't correspond directly to the model's attributes, so the changes just get stripped out.

I guess the quick fix for now is to just call index_document instead of update_document after update, because that doesn't try to check for changes. Any thoughts on this?

from elasticsearch-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.