Skip to content

Commit ceef80e

Browse files
bogdanvlvivkarmi
authored andcommitted
[MODEL] Added information about elasticsearch-dsl to the README
Closes elastic#574 [ci skip]
1 parent 6d10abb commit ceef80e

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

elasticsearch-model/README.md

+21-2
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,8 @@ response.results.first.highlight.title
320320
# ["Quick brown <em>fox</em>"]
321321
```
322322

323-
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:
325325

326326
```ruby
327327
require 'jbuilder'
@@ -341,6 +341,25 @@ response.results.first.title
341341
# => "Quick brown fox"
342342
```
343343

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 :title do
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+
344363
### Index Configuration
345364

346365
For proper search engine function, it's often necessary to configure the index properly.

0 commit comments

Comments
 (0)