Skip to content

Commit ec214a0

Browse files
authored
DATAES-758 - Fix documentation for @query annotation.
Original PR: spring-projects#403
1 parent 251adc1 commit ec214a0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/main/asciidoc/reference/elasticsearch-repository-queries.adoc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ Repository methods can be defined to have the following return types for returni
274274
* `Stream<T>`
275275
* `SearchHits<T>`
276276
* `List<SearchHits<T>>`
277-
* `Stream<>>SearchHit<T>>`
277+
* `Stream<SearchHit<T>>`
278+
* `SearchPage<T>`
278279

279280
[[elasticsearch.query-methods.at-query]]
280281
== Using @Query Annotation
@@ -284,8 +285,21 @@ Repository methods can be defined to have the following return types for returni
284285
[source,java]
285286
----
286287
interface BookRepository extends ElasticsearchRepository<Book, String> {
287-
@Query("{\"bool\" : {\"must\" : {\"field\" : {\"name\" : \"?0\"}}}}")
288+
@Query("{\"match\": {\"name\": {\"query\": \"?0\"}}}")
288289
Page<Book> findByName(String name,Pageable pageable);
289290
}
290291
----
292+
The String that is set as the annotation argument must be a valid Elasticsearch JSON query. It will be sent to Easticsearch as value of the query element; if for example the function is called with the parameter _John_, it would produce the following query body:
293+
[source,json]
294+
----
295+
{
296+
"query": {
297+
"match": {
298+
"name": {
299+
"query": "John"
300+
}
301+
}
302+
}
303+
}
304+
----
291305
====

0 commit comments

Comments
 (0)