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?

Community
  • 1
  • 1
wired00
  • 13,930
  • 7
  • 70
  • 73
  • 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. – Jettro Coenradie Jul 26 '16 at 06:02
  • @JettroCoenradie just checking versions now thanks – wired00 Jul 26 '16 at 06:05
  • Hmm So with Jhipster generator, and for some reason its come packaged with 1.5.2 and spring-data-elasticsearch 1.3.4... :/ – wired00 Jul 26 '16 at 06: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? – Jettro Coenradie Jul 26 '16 at 06: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 – wired00 Jul 26 '16 at 06:13
  • Not a big fan of the spring data elastic component. Did use it for a project, but for all other projects I am doing it myself. Often the elasticsearch part deviates a lot from the other model in the database for instance that for me it was a lot better not to use to much of the generated spring data stuff. But that does not help you with your problem. Val gave you the right answer :-) – Jettro Coenradie Jul 26 '16 at 06:39
  • Thanks @JettroCoenradie, I will certainly consider that – wired00 Jul 26 '16 at 07:19

1 Answers1

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\"}}}}")
Val
  • 207,596
  • 13
  • 358
  • 360
  • 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 – wired00 Jul 26 '16 at 06:04
  • Yes, that's a documentation bug that needs to be fixed. – Val Jul 26 '16 at 06:05
  • ok working perfect now with `term` instead of field and escaped double quotes cheers guys – wired00 Jul 26 '16 at 06:14