Comments (3)
Hi @satyakampandya, thanks for the feature request. However, I don't understand the problem you're try to solve. Can you share more about the specific problem, and possibly a code example of what you're envisioning?
from searchkick.
Scenario:
In my codebase, I am handling Elasticsearch connectivity issues by rescuing Faraday::TimeoutError. However, this approach causes issues with my existing code that relies on @products for fetching suggestions.
def retrieve_products
@products = base_elasticsearch
rescue Faraday::TimeoutError
@products = []
end
Proposed Solution:
To address this issue, I propose the creation of a new method called none that sets @products, allowing to gracefully handle Elasticsearch downtime without breaking your existing codebase.
def retrieve_products
@products = base_elasticsearch
rescue Faraday::TimeoutError
@products = Searchkick::Results.none
# Alternatively, you can use a custom `none` method:
# @products = Product.search(none: true)
end
searcher = build_searcher(search_params)
products = searcher.retrieve_products
products_suggestions = products.suggestions
# products.suggestions will work, it'll return [] if Elasticsearch is down
required_hits = (10 - products_suggestions.count)
# products_suggestions.count will work, it'll return 0 if Elasticsearch is down
This approach ensures that your existing code can continue to use @products without disruption, and it provides a more structured way to handle Elasticsearch downtime using the none method.
In summary, this proposal introduces a new method to gracefully handle exceptions while maintaining the stability of your codebase in situations where Elasticsearch is unavailable.
from searchkick.
Thanks for the additional explanation. However, I don't see a strong reason for including it in the gem (users can do nil
checks or implement their own null objects as needed).
from searchkick.
Related Issues (20)
- Add documentation for client_options HOT 1
- Lazy load not working HOT 2
- named query search example (_name) HOT 1
- Scoped include in search_import not being loaded HOT 1
- Unable to index model with composite pk HOT 1
- `scroll_each` API to work with batches like `find_each`
- While using opensearch-ruby got error: end of file reached (Faraday::ConnectionFailed) HOT 1
- Default index name doesn't use UTC time HOT 1
- minor issue when when doing a full reindex in queue mode HOT 1
- Make "Searchkick.search" for multi-model searches work with Rails low-level caching HOT 4
- Why is `_script` filters commented out in the source code? Possible to add support for scripts? HOT 2
- Index different objects to different indices HOT 2
- Integrate partial reindexing with mode_async bulk reindexing
- `scope_results` outputs incorrect warnings HOT 1
- rails production env indexmissing issue HOT 1
- Ability to set body_options globally in the same way you can model_options
- Clarify use of ActiveRecord `where` in `search_import` HOT 1
- Unable to load dynamic synonyms with Elastic HOT 1
- Support for Dynamoid (DynamoDB) HOT 2
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 searchkick.