stretcher 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -29,17 +29,18 @@ server = Stretcher::Server.new('http://localhost:9200')
29
29
  # Delete an index (in case you already have this one)
30
30
  server.index(:foo).delete rescue nil
31
31
  # Create an index
32
- server.index(:foo).create(mappings: {tweet: {properties: {text: 'string'}}})
33
- # Add a document
34
- server.index(:foo).type(:tweet).put(123, {text: 'Hello'})
32
+ server.index(:foo).create(mappings: {tweet: {properties: {text: {type: 'string'}}}})
33
+ # Add some documents
34
+ 30.times {|t| server.index(:foo).type(:tweet).put(t, {text: "Hello #{t}"}) }
35
35
  # Retrieve a document
36
- server.index(:foo).type(:tweet).get(123)
36
+ server.index(:foo).type(:tweet).get(3)
37
+ # => #<Hashie::Mash text="Hello 3">
37
38
  # Perform a search (Returns a Stretcher::SearchResults instance)
38
- res = server.index(:foo).search({size: 12}, {query: {match_all: {}}})
39
+ res = server.index(:foo).search(size: 12, query: {match_all: {}})
39
40
  res.class # Stretcher::SearchResults
40
- res.total # => 1
41
+ res.total # => 30
42
+ res.results # => [#<Hashie::Mash _id="4" text="Hello 4">, ...]
41
43
  res.facets # => nil
42
- res.results # => [#<Hashie::Mash _id="123" text="Hello">]
43
44
  res.raw # => #<Hashie::Mash ...> Raw JSON from the search
44
45
  ```
45
46
 
@@ -50,10 +51,10 @@ res.raw # => #<Hashie::Mash ...> Raw JSON from the search
50
51
  # with_server takes the same args as #new, but is amenable to blocks
51
52
  Stretcher::Server.with_server('http://localhost:9200') {|srv|
52
53
  srv.index(:foo) {|idx|
53
- idx.type(:bar) {|t| [t.exists?, t.get_mapping] }
54
+ idx.type(:tweet) {|t| {exists: t.exists?, mapping: t.get_mapping} }
54
55
  }
55
56
  }
56
- # => [true, #<Hashie::Mash bar=...>]
57
+ # => {:exists=>true, :mapping=>#<Hashie::Mash tweet=...>}
57
58
  ```
58
59
 
59
60
  ### Multi Search
@@ -74,6 +75,11 @@ docs = [{"_type" => "tweet", "_id" => 91011, "text" => "Bulked"}]
74
75
  server.index(:foo).bulk_index(docs)
75
76
  ```
76
77
 
78
+ ### Rails Integration
79
+
80
+ Stretcher is a low level-client, but it was built as a part of a full suite of Rails integration tools.
81
+ While not yet open-sourced, you can read our detailed blog post: [integrating Stretcher with Rails](http://blog.andrewvc.com/elasticsearch-rails-stretcher-at-pose).
82
+
77
83
  ### Full Documentation
78
84
 
79
85
  This README documents only part of stretcher's API. The full documentation for stretcher is available in its [full rdocs](http://rdoc.info/github/PoseBiz/stretcher/master/frames).
@@ -81,10 +81,18 @@ module Stretcher
81
81
  # res.facets # => nil
82
82
  # res.results # => [#<Hashie::Mash _id="123" text="Hello">]
83
83
  # res.raw # => #<Hashie::Mash ...> Raw JSON from the search
84
- def search(query_opts={}, body=nil)
85
- uri = path_uri('/_search?' + Util.querify(query_opts))
86
- logger.info { "Stretcher Search: curl -XGET #{uri} -d '#{body.to_json}'" }
87
- response = @server.request(:get, uri) do |req|
84
+ def search(generic_opts={}, explicit_body=nil)
85
+ uri_str = '/_search'
86
+ body = nil
87
+ if explicit_body
88
+ uri_str << '?' + Util.querify(generic_opts)
89
+ body = explicit_body
90
+ else
91
+ body = generic_opts
92
+ end
93
+
94
+ logger.info { "Stretcher Search: curl -XGET '#{uri}' -d '#{body.to_json}'" }
95
+ response = @server.request(:get, path_uri(uri_str)) do |req|
88
96
  req.body = body
89
97
  end
90
98
  SearchResults.new(raw: response)
@@ -71,8 +71,8 @@ module Stretcher
71
71
  end
72
72
 
73
73
  # Issues an Index#search scoped to this type
74
- def search(query_opts={}, body=nil)
75
- @index.search(query_opts.merge(type: name), body)
74
+ def search(generic_opts={}, body=nil)
75
+ @index.search(generic_opts.merge(type: name), body)
76
76
  end
77
77
 
78
78
  # Full path to this index type
@@ -1,3 +1,3 @@
1
1
  module Stretcher
2
- VERSION = "1.2.0"
2
+ VERSION = "1.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stretcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-05 00:00:00.000000000 Z
12
+ date: 2013-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday