Created
February 14, 2011 23:05
-
-
Save lukas-vlcek/826776 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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