Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexes are not refreshing, even with refresh_interval being set #1039

Open
crimson-knight opened this issue Aug 26, 2022 · 0 comments
Open

Comments

@crimson-knight
Copy link

crimson-knight commented Aug 26, 2022

I ran into this situation after doing a ruby & rails upgrade (rails 6.0.x -> 6.1.x, ruby 2.7.x -> ruby 3.1.x)

We have a model setup similarly to this:

class Voter < ApplicationRecord
  include Elasticsearch::Model
  
  # ...
  # All kinds of business code
  # ..
  
  settings index: {
    analysis: {
      tokenizer: {
        autocomplete: {
          type: :edge_ngram,
          min_gram: 2,
          max_gram: 10,
          token_chars: [
            :letter,
            :digit
          ]
        }
      },
      analyzer: {
        folding: {
          tokenizer: :standard,
          filter: [ :lowercase, :asciifolding ]
        },
        autocomplete: {
          tokenizer: :autocomplete,
          filter: [
            :lowercase,
            :asciifolding
          ]
        },
        autocomplete_search: {
          tokenizer: :lowercase
        }
      }
    }
  } do
    mappings dynamic: false do
      # Specify a bunch of indexes in here
    end
  end
end

This was working before we did the upgrade. Here's the command and diff output to show the gem versions that changed:

git diff master Gemfile.lock | grep elastic
-    elasticsearch (7.9.0)
-      elasticsearch-api (= 7.9.0)
-      elasticsearch-transport (= 7.9.0)
-    elasticsearch-api (7.9.0)
+    elasticsearch (7.13.3)
+      elasticsearch-api (= 7.13.3)
+      elasticsearch-transport (= 7.13.3)
+    elasticsearch-api (7.13.3)
-    elasticsearch-model (7.1.1)
+    elasticsearch-model (7.2.1)
-      elasticsearch (> 1)
+      elasticsearch (~> 7)
-    elasticsearch-rails (7.1.1)
-    elasticsearch-transport (7.9.0)
+    elasticsearch-rails (7.2.1)
+    elasticsearch-transport (7.13.3)
-  elasticsearch-model (~> 7.x)
-  elasticsearch-rails (~> 7.x)
+  elasticsearch (< 7.14)
+  elasticsearch-model (~> 7.2.1)
+  elasticsearch-rails (~> 7.2.1)

Expected Behavior:

When a voter is created and indexed, the searching the index should return the voter. This is how everything worked on the previous gem versions.

Attempted solution

I experimented and added refresh_interval: "1s" to our settings hash, and the expected behavior has resumed.

class Voter < ApplicationRecord
  include Elasticsearch::Model
  
  # ...
  # All kinds of business code
  # ..
  
  settings index: {
    refresh_interval: "1s",
    analysis: {
      # same as above
      },
      analyzer: {
        # same as above
        },
        autocomplete: {
          # same as above
        },
        autocomplete_search: {
          # same as above
        }
      }
    }
  } do
    mappings dynamic: false do
      # Specify a bunch of indexes in here
    end
  end
end

This worked temporarily then stopped working. I've now had to add Voter.__elasticsearch__.refresh_index! for the updates in the index to appear.

We have other models that the indexes are updating, but they are not using the index: {} hash in the settings method at all. This seems to be the only outlying difference.

@crimson-knight crimson-knight changed the title refresh_interval being unset if a value is not specified when using settings Indexes are not refreshing, even with refresh_interval being set Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant