Skip to content

Instantly share code, notes, and snippets.

@lukas-vlcek
Created February 14, 2011 23:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukas-vlcek/826776 to your computer and use it in GitHub Desktop.
Save lukas-vlcek/826776 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'net/http'
require 'yaml'
require 'json'
# kill the index
delete = Net::HTTP::Delete.new("/test")
# create again
create_index = Net::HTTP::Post.new("/test")
create_index.body = {
'settings' => {
'analysis' => {
'analyzer' => {
'myAnalyzer' => {
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => ['standard', 'lowercase', 'porterStem']
}
}
}
}
}.to_yaml
# and use myAnalyzer in the below code
# index a record
index_record = Net::HTTP::Put.new("/test/foo/1")
index_record.body = {"text" => "i like to go for a walk"}.to_json
# do a search which requires stemming to succeed
search = Net::HTTP::Get.new("/test/_search?pretty=true&q=walking")
# perform requests
Net::HTTP.start("localhost", 9200) do |http|
[delete, create_index, index_record, search].each do |request|
puts http.request(request)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment