1

When I use the following code as Spring docs said eclipse always show Syntax error on token.

public interface BookRepository extends ElasticsearchRepository<Book, String> {
@Query("{"bool" : {"must" : {"field" : {"name" : "?0"}}}}")
Page<Book> findByName(String name,Pageable pageable);}
1
  • Which token exactly is Eclipse complaining about? Commented Aug 28, 2015 at 4:27

2 Answers 2

3

I suspect it doesn't like the query inside the @Query annotation. You need to escape the double quotes in your query.

public interface BookRepository extends ElasticsearchRepository<Book, String> {
@Query("{\"bool\" : {\"must\" : {\"field\" : {\"name\" : \"?0\"}}}}")
Page<Book> findByName(String name,Pageable pageable);}

That's a documentation bug, indeed. In their tests, however, we can find out that the doubles quotes must be escaped, since the double quote is a reserved delimiter character in Java.

Sign up to request clarification or add additional context in comments.

Comments

0

Copy your JSON query (under "query": {, without the query tag).

Write @Query("") in your code and paste your copied query inside the quotes, your IDE will probably automatically escape the query.

Useful for long queries.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.