Giter Club home page Giter Club logo

Comments (9)

pyromaniac avatar pyromaniac commented on May 27, 2024

Howdy! I'm not sure you really need this. I think it is much more effective to reset the whole index. Because the whole index might be just deleted completely, but as for types - ES can't do something similar and you have to delete documents from index manually. And I'm not sure it can be done using type condition. The deletion happens in batches and you have to pass all the documents ids you want to delete. This approach seems to be quite slow.

However if you still need this or I'm wrong about the way to perform it - I'd like to see it more like MyIndex::MyType.reset!. As type object method.

from chewy.

jondavidford avatar jondavidford commented on May 27, 2024

The reason why I thought this would be useful for me is because I need to periodically update all the elements of a single type in my index (for permissioning) and the number of documents in this type is very small compared to the overall size of the index. So I think it is more efficient for me to just update that type.

I was thinking use the delete by query api (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-delete-by-query.html) to delete all the documents of that type, then use bulk api to index the new documents of that type with updated info. Does that make sense? You're right, it should be a type object method if anything.

from chewy.

pyromaniac avatar pyromaniac commented on May 27, 2024

Ah, there is delete by query api. So yep, you can add MyIndex::MyType.delete and MyIndex::MyType.reset methods (and maybe bang methods as well). It will be conform enough and convenient in some cases such as yours.

from chewy.

pyromaniac avatar pyromaniac commented on May 27, 2024

Oh, I've thought it will be even much better to add delete_all method to query. And use it in reset. What do you think?

from chewy.

jondavidford avatar jondavidford commented on May 27, 2024

Sorry, could you clarify what you mean?

from chewy.

pyromaniac avatar pyromaniac commented on May 27, 2024

I mean we can do it like this: MyIndex.query(...).filter { ... }.delete_all. And this will delete all the documents matching this query. It is very similar to activerecord's delete_all scope method.
After we would be able to implement reset method like this:

def Chewy::Type::Base.reset
  delete_all
  import
end

from chewy.

jondavidford avatar jondavidford commented on May 27, 2024

Ah yes, that looks good. I'll work on it and make a PR

from chewy.

pyromaniac avatar pyromaniac commented on May 27, 2024

Awesome, thanks!

from chewy.

jondavidford avatar jondavidford commented on May 27, 2024

#55

from chewy.

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.