简体   繁体   中英

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)

在此输入图像描述

I've attempted to escape the quotes, but the resulting elastic query does not work with below exception:

在此输入图像描述

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM