You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.6 KiB

  1. enabled = ENV['ES_ENABLED'] == 'true'
  2. host = ENV.fetch('ES_HOST') { 'localhost' }
  3. port = ENV.fetch('ES_PORT') { 9200 }
  4. fallback_prefix = ENV.fetch('REDIS_NAMESPACE') { nil }
  5. prefix = ENV.fetch('ES_PREFIX') { fallback_prefix }
  6. Chewy.settings = {
  7. host: "#{host}:#{port}",
  8. prefix: prefix,
  9. enabled: enabled,
  10. journal: false,
  11. sidekiq: { queue: 'pull' },
  12. }
  13. # We use our own async strategy even outside the request-response
  14. # cycle, which takes care of checking if ElasticSearch is enabled
  15. # or not. However, mind that for the Rails console, the :urgent
  16. # strategy is set automatically with no way to override it.
  17. Chewy.root_strategy = :custom_sidekiq
  18. Chewy.request_strategy = :custom_sidekiq
  19. Chewy.use_after_commit_callbacks = false
  20. module Chewy
  21. class << self
  22. def enabled?
  23. settings[:enabled]
  24. end
  25. end
  26. end
  27. # ElasticSearch uses Faraday internally. Faraday interprets the
  28. # http_proxy env variable by default which leads to issues when
  29. # Mastodon is run with hidden services enabled, because
  30. # ElasticSearch is *not* supposed to be accessed through a proxy
  31. Faraday.ignore_env_proxy = true
  32. # Elasticsearch 7.x workaround
  33. Elasticsearch::Transport::Client.prepend Module.new {
  34. def search(arguments = {})
  35. arguments[:rest_total_hits_as_int] = true
  36. super arguments
  37. end
  38. }
  39. Elasticsearch::API::Indices::IndicesClient.prepend Module.new {
  40. def create(arguments = {})
  41. arguments[:include_type_name] = true
  42. super arguments
  43. end
  44. def put_mapping(arguments = {})
  45. arguments[:include_type_name] = true
  46. super arguments
  47. end
  48. }