底线- 如何将我的简单过滤器查询转换为弹簧数据弹性搜索?任何线索表示赞赏。谢谢
我一直在尝试使用弹簧数据弹性搜索编写以下渗透查询
"query": {
"percolate": {
"field": "query",
"document": {
"message": "A new bonsai tree in the office"
}
}
}
我试过了
Criteria criteria = new Criteria("query").is(
new Criteria("percolate")
.is(
new Criteria("field").is("query")
.and("document")
.is(new Criteria("message").is(text))
)
);
试过了
Query query = new StringQuery(String.format("{\n" +
" \"query\": {\n" +
" \"percolate\": {\n" +
" \"field\": \"query\",\n" +
" \"document\": {\n" +
" \"message\": \"%s\"\n" +
" }\n" +
" }\n" +
" }\n" +
"}",text));
还尝试了 NativeSearchQuery,但都没有奏效。
我看到https://tothepoint.group/matching-documents-with-elasticsearch-percolator-query/作者使用 PercolateQueryBuilder (https://github.com/ophalsp/elasticsearch-percolator),但我没有在 spring 数据中看到 PercolateQueryBuilder弹性搜索。
编辑:- 我尝试了所有实现 QueryBuilder 的构建器。由于它们都没有在 XContentBuilder 构建器中查询或渗透(如下所示),因此它们不起作用
protected void doXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject("query");
我还可以看到 PercolateQueryBuilder 是 percolator-client 的一部分,它是 org.elasticsearch.client.transport 的一部分,它在 spring-boot 中被排除在外
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>4.2.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>transport</artifactId>
<groupId>org.elasticsearch.client</groupId>
</exclusion>
</exclusions>
</dependency>
我将添加 org.elasticsearch.client.transport 并试一试。