使用@Query编写dao进行弹性搜索

时间:2018-08-14 05:51:42

标签: elasticsearch

我有一个完美的curl查询

curl -X GET "localhost:9200/countries_reference_book/_search" -H 'Content-Type: application/json' -d'{"_source": {"includes": [ "tours.id"]},"query": {"bool": {"must": [{ "match":{ "departureDestination.departureCityId": "392" }},{ "match": { "departureDestination.destinationCountryId":  "146695" }}]}}}'

我想使用@Query将此查询传递给dao方法,我的解决方案如下

@Query("{\"_source\": [ \"tours.id\"], \"query\":  {\"bool\": {\"must\": [{ \"match\":{ \"departureDestination.departureCityId\": ?0 }}, { \"match\": { \"departureDestination.destinationCountryId\": ?1 }}]}}}")
    List<Integer> getTourIdsBetweenDepartureCityAndDepartureCountry(int departureCityId, int destinationCountry);

但它不起作用,我收到此错误

org.elasticsearch.common.ParsingException: [_source] query malformed, no start_object after query name
    at org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder(AbstractQueryBuilder.java:314) ~[elasticsearch-5.6.10.jar:5.6.10]

我该如何正确地为dao编写查询,谢谢

0 个答案:

没有答案