wired00 wired00 - 1 year ago 182
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
Answer Source

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\"}}}}")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download