wired00 wired00 - 6 months ago 87
Java Question

Invalid custom @Query syntax Spring Elastic Search

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


...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

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

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\"}}}}")