Created
February 8, 2013 11:20
-
-
Save dedico/4738258 to your computer and use it in GitHub Desktop.
Stretcher - readme example
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 'stretcher' | |
# First Create a server | |
server = Stretcher::Server.new('http://localhost:9200') | |
# Delete an index (in case you already have this one) | |
server.index(:foo).delete rescue nil | |
# Create an index | |
server.index(:foo).create(mappings: {tweet: {properties: {text: 'string'}}}) | |
# and here I get following exception: | |
# /Users/marek/.rvm/gems/ruby-1.9.3-p194/gems/stretcher-1.2.0/lib/stretcher/server.rb:136:in `request': Error processing request (400)! put URL: http://localhost:9200/foo/ (Stretcher::RequestError) | |
# Resp Body: #<Hashie::Mash error="MapperParsingException[mapping [tweet]]; nested: ClassCastException[java.lang.String cannot be cast to java.util.Map]; " status=400> | |
# from /Users/marek/.rvm/gems/ruby-1.9.3-p194/gems/stretcher-1.2.0/lib/stretcher/index.rb:41:in `create' | |
# from stretcher_search.rb:8:in `<main>' | |
# Add a document | |
server.index(:foo).type(:tweet).put(123, {text: 'Hello'}) | |
# Retrieve a document | |
server.index(:foo).type(:tweet).get(123) | |
# Perform a search (Returns a Stretcher::SearchResults instance) | |
res = server.index(:foo).search({size: 12}, {query: {match_all: {}}}) | |
res.class # Stretcher::SearchResults | |
res.total # => 1 | |
res.facets # => nil | |
res.results # => [#<Hashie::Mash _id="123" text="Hello">] | |
res.raw # => #<Hashie::Mash ...> Raw JSON from the search |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ah, that is a typo, should have been: server.index(:foo).create(mappings: {tweet: {properties: {text: {type: 'string'}}}})
I'll update the README soon.