wired00 wired00 - 4 months ago 59
Java Question

Invalid custom @Query syntax Spring Elastic Search

Can someone shed light on this, I've followed the example here:

http://docs.spring.io/spring-data/elasticsearch/docs/1.3.4.RELEASE/reference/html/#elasticsearch.query-methods.at-query

...However, the syntax cannot possibly work. It results in syntax errors similar to below image. (Needless to say this does not compile)

enter image description here

I've attempted to escape the quotes, but the resulting

elastic
query does not work with below exception:

enter image description here

The thing is, other examples I've found are using the similar format and of course don't work:
Spring Data elasticsearch @Query annotation for nested objects

Any ideas?

Val Val
Answer

You have two issues:

A. The field query does not exist anymore, you need to use either match or term (the error message says "no query registered for [field]")

{"bool": {"must": {"term": {"name": "?0"}}}}

B. You need to escape the double quotes inside your query (as you can see your IDE is red-lining your query)

@Query("{\"bool\": {\"must\": {\"term\": {\"name\": \"?0\"}}}}")