You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can pass any object which implements a `to_hash` method, or you can use your favourite JSON builder
324
-
to build the search definition as a JSON string:
323
+
You can pass any object which implements a `to_hash` method, which is called automatically,
324
+
so you can use a custom class or your favourite JSON builder to build the search definition:
325
325
326
326
```ruby
327
327
require'jbuilder'
@@ -341,6 +341,25 @@ response.results.first.title
341
341
# => "Quick brown fox"
342
342
```
343
343
344
+
Also, you can use the [**`elasticsearch-dsl`**](https://github.com/elastic/elasticsearch-ruby/tree/master/elasticsearch-dsl) library, which provides a specialized Ruby API for
345
+
the Elasticsearch Query DSL:
346
+
347
+
```ruby
348
+
require'elasticsearch/dsl'
349
+
350
+
query =Elasticsearch::DSL::Search.search do
351
+
query do
352
+
match :titledo
353
+
query 'fox dogs'
354
+
end
355
+
end
356
+
end
357
+
358
+
response =Article.search query
359
+
response.results.first.title
360
+
# => "Quick brown fox"
361
+
```
362
+
344
363
### Index Configuration
345
364
346
365
For proper search engine function, it's often necessary to configure the index properly.
0 commit comments