Skip to content

Instantly share code, notes, and snippets.

@jiren
Created November 1, 2013 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiren/7263138 to your computer and use it in GitHub Desktop.
Save jiren/7263138 to your computer and use it in GitHub Desktop.
Elasticsearch: Remove stem words from index data using snowball analyzer.
require 'elasticsearch'
require 'pp'
index_name = 'test'
@client = Elasticsearch::Client.new log: true
@client.indices.delete(index: index_name) rescue ''
@client.indices.create index: index_name,
body: {
settings: {
analysis: {
analyzer: {
default: {
type: 'snowball',
}
},
}
},
mappings: {
document: {
properties: {
text: { type: 'string' }
}
}
}
}
['Playing', 'played', 'plays', 'player'].each do |text|
@client.index(index: index_name, type: 'doc', body: {text: text})
end
@client.indices.refresh index: index_name
pp @client.search(index: index_name, q: 'play')
pp @client.search(index: index_name, q: 'plays')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment