Comments (9)
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.
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.
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.
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.
Sorry, could you clarify what you mean?
from chewy.
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.
Ah yes, that looks good. I'll work on it and make a PR
from chewy.
Awesome, thanks!
from chewy.
from chewy.
Related Issues (20)
- Mapping fields is not working after upgrade from version 5
- Index field looses date precision if type not explicitly set to `date` (and causes sync to always update all documents)
- Unknown key for a START_ARRAY in [index].
- How do I connect to an Elastic instance at https://cloud.elastic.co/
- Bug in the `mock_elasticsearch_response_sources` method
- Redundant crutch call when :update_fields does not contain related field
- bundle gem chewy 7.2.x auto install gem elasticsearch 8.x ?? HOT 8
- A particular search term returns a result count, but the wrappers are empty HOT 6
- Support PITs (points in time) and search_after HOT 4
- is there a way to set `Chewy.strategy(:lazy_sidekiq)` globally? to make all updates asynchronously HOT 2
- Readme comment on Ruby 3 + Rails 6.1
- `Elasticsearch::Transport::Transport::Errors::Found`
- Cleanup journal throws `Yajl::EncodeError: Max nesting depth of 256 exceeded`
- Old indices are not being cleared up after a reset
- Port PR #874 to the 7.0.x branch
- Trying to use Pagy pagination with Chewy, running into autoloading will_paginate gem
- Breaking change at 7.2.4
- I have a question regarding elasticsearch-ruby gem
- Support rails parallel testing
- Warning when upgrading to Rails 7.1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chewy.