2

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?

7
  • what version of elasticsearch are you running? Check the required version of the elasticsearch data library. If I am right they depend on elastic 1.5.4 which is old. If you are running elastic 2.x, it won't work. If you upgrade to the 2.x version of spring-data elasticsearch it will be a lot better. With elastic 5 the client will have a lot less impact on the used version of the server. But is is wise to have a good look. Commented Jul 26, 2016 at 6:02
  • @JettroCoenradie just checking versions now thanks Commented Jul 26, 2016 at 6:05
  • Hmm So with Jhipster generator, and for some reason its come packaged with 1.5.2 and spring-data-elasticsearch 1.3.4... :/ Commented Jul 26, 2016 at 6:08
  • The question is, what version of elasticsearch are you running? Do you have a separate elasticsearch node or are you using the embedded one? Commented Jul 26, 2016 at 6:10
  • I meant its elasticsearch 1.5.2, just testing now with term. Its bizaar the documenation is wrong even on the latest 2.x release doc Commented Jul 26, 2016 at 6:13

1 Answer 1

4

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\"}}}}")
Sign up to request clarification or add additional context in comments.

3 Comments

ACK, I was just coming to that realisation based on the link in the comment you gave previously, big help, just looking into it now
Yes, that's a documentation bug that needs to be fixed.
ok working perfect now with term instead of field and escaped double quotes cheers guys

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.