在spring-boot-starter-data-elasticsearch中建议查询不起作用

时间:2019-07-27 12:16:24

标签: spring-boot elasticsearch autocomplete spring-data-elasticsearch

我正在尝试使用spring-boot-starter-data-elasticsearch执行建议查询。而像这样的字词查询:

@Query(value = "{\"term\" : { \"questionElasticSearch\" : \"?0\" }}") List<QuestionElasticSearch> getSuggestions2(String questionElasticSearch);

正在工作,像这样的建议查询:

@Query("{\"suggest\": {\"song-suggest\" : {\"prefix\" : \"?0\",\"completion\" : {\"field\" : \"questionElasticSearch\"}}}}") List<QuestionElasticSearch> getSuggestions(String questionElasticSearch);

不是。抛弃“建议”和“建议”仍然会出错。正在获取:

org.elasticsearch.common.ParsingException:没有为[建议]注册任何[查询]     在org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder(AbstractQueryBuilder.java:337)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.index.query.WrapperQueryBuilder.doRewrite(WrapperQueryBuilder.java:165)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.index.query.AbstractQueryBuilder.rewrite(AbstractQueryBuilder.java:284)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.search.builder.SearchSourceBuilder.rewrite(SearchSourceBuilder.java:949)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.search.builder.SearchSourceBuilder.rewrite(SearchSourceBuilder.java:80)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.index.query.Rewriteable.rewriteAndFetch(Rewriteable.java:97)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.index.query.Rewriteable.rewriteAndFetch(Rewriteable.java:87)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.action.search.TransportSearchAction.doExecute(TransportSearchAction.java:216)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.action.search.TransportSearchAction.doExecute(TransportSearchAction.java:70)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.action.support.TransportAction $ RequestFilterChain.proceed(TransportAction.java:167)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:139)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.action.support.HandledTransportAction $ TransportHandler.messageReceived(HandledTransportAction.java:89)〜[elasticsearch-6.4.3.jar:6.4.3]     在org.elasticsearch.action.support.HandledTransportAction $ TransportHandler.messageReceived(HandledTransportAction.java:80)〜[elasticsearch-6.4.3.jar:6.4.3]

有什么主意吗?

1 个答案:

答案 0 :(得分:0)

Spring Data Elasticsearch通过定义@Document类型的Completion带注释类的字段,为完成字段的正确映射和索引提供了一些基本支持。

但是查询支持仅存在于使用ElasticsearchTemplate的{​​{1}}类中,该类在Elasticsearch 7.0中已弃用,并将在8中删除,因此也将从Spring中删除。 ES的受支持版本更改为8时为Data Elasticsearch(可能在5.x中)。 此基本实现从未添加到TransportClient类中,ElasticsearchRestTemplate实现中也缺少它-这会导致您看到错误。

因此,您可以使用Spring Data Elasticsearch以所需的格式存储数据,但不能查询它。我创建了a Jira issue for this