Skip to content

Instantly share code, notes, and snippets.

@wireframe
wireframe / elasticsearch_testcase.rb
Created February 2, 2011 20:11
teardown/recreate index for testcases
require 'rubygems'
require 'rubberband'
index = 'foo'
type = 'bar'
searcher = ElasticSearch.new("localhost:9200", :index => index, :type => type)
searcher.delete_index(index) rescue nil
searcher.create_index index
searcher.index({:name => 'foo'})
searcher.refresh
curl -XDELETE 'http://localhost:9200/foo'
curl -XPUT 'http://localhost:9200/foo' -d '
{
index: {}
}
'
curl -XPUT 'http://localhost:9200/foo/bar/123' -d '
{
name: "baz"
}
@wireframe
wireframe / elasticsearch_refresh_testcase.sh
Created February 4, 2011 16:29
index, refresh, search
curl -XDELETE 'http://localhost:9200/foo/bar'
curl -XPUT 'http://localhost:9200/foo/bar/123' -d '
{
name: "baz"
}
'
curl -XPOST 'http://localhost:9200/foo/_refresh'
curl -XGET 'http://localhost:9200/foo/bar/_search?q=baz&size=10'
curl -XPUT localhost:9200/_percolator/elastic_searchable/myfilter -d '{
query: {
query_string: {
query: "foo"
}
}
}'
curl -XPOST localhost:9200/_percolator/_refresh
curl -XPUT localhost:9200/elastic_searchable/books/1?percolate=* -d '{
title: "foo bar"
curl -XDELETE http://localhost:9200/test
curl -XPUT http://localhost:9200/test -d "
{\"analysis.analyzer.default.tokenizer\":\"standard\",\"mappings\":{\"users\":{\"properties\":{\"name\":{\"index\":\"not_analyzed\",\"type\":\"string\"}}}},\"analysis.analyzer.default.filter\":[\"standard\",\"lowercase\",\"porterStem\"]}
"
curl http://localhost:9200/test/_status | jsonpretty
#!/bin/bash
# error in log output
# [2011-04-12 17:07:03,319][DEBUG][action.admin.indices.status] [Foster, Tom] [foo][2], node[-Dbau_mxSR2TtFDAsvncyQ], [P], s[INITIALIZING]: Failed to execute [org.elasticsearch.action.admin.indices.status.IndicesStatusRequest@2a2e0135]
# org.elasticsearch.index.IndexShardMissingException: [foo][2] missing
# at org.elasticsearch.index.service.InternalIndexService.shardSafe(InternalIndexService.java:165)
# at org.elasticsearch.action.admin.indices.status.TransportIndicesStatusAction.shardOperation(TransportIndicesStatusAction.java:148)
# at org.elasticsearch.action.admin.indices.status.TransportIndicesStatusAction.shardOperation(TransportIndicesStatusAction.java:57)
# at org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction$AsyncBroadcastAction.performOperation(TransportBroadcastOperationAction.java:238)
# at org.elasticsearch.action.support.broadcast.TransportBroadcastOperationAction$AsyncBroadcastAction.access$200(TransportBroadcastOperationA
{
"cluster_name" : "elasticsearch",
"master_node" : "-Dbau_mxSR2TtFDAsvncyQ",
"blocks" : {
},
"nodes" : {
"-Dbau_mxSR2TtFDAsvncyQ" : {
"name" : "Foster, Tom",
"transport_address" : "inet[/10.0.1.4:9300]",
"attributes" : {
@wireframe
wireframe / be_lintable.rb
Created June 23, 2011 16:29
be_lintable.rb
require 'jslint'
# "var someJsExpresion = 'stuff';".should be_lintable
RSpec::Matchers.define :be_lintable do |expected|
match do |actual|
tmp_js_output_dir = Rails.root.join('tmp', 'js_lintable')
FileUtils.mkdir_p tmp_js_output_dir unless File.exists?(tmp_js_output_dir)
tmp_js_output = File.join(tmp_js_output_dir, 'output.js')
# add helper methods
class String
def inspect_bytes
index = 0
self.each_byte do |b|
puts "#{index}: #{b} => #{b.chr}"
index += 1
end
end
def convert_to_utf8
module ActiveRecord::ConnectionAdapters::DatabaseStatements
def select_all_with_explain_plan(sql, name = nil)
missing_indexes = select_all_without_explain_plan("EXPLAIN #{sql}", "explain plan").reject {|r| r['key'] }
raise "Missing dataabase indexes: #{missing_indexes.inspect}" if missing_indexes.any?
select_all_without_explain_plan(sql, name)
end
alias_method_chain :select_all, :explain_plan
end