@查询匹配_全部功能

问题描述 投票:0回答:1

我是 spring data elasticsearch 的新手,我想实现这个剩余查询

GET _search
{"query": {

"match": {
  "_all": "...myquerystring..."
}
}
}

@Query注解这样写:

@Query("{\"match\":{\"_all\":\"?0\"}}") 

然后我就不知道怎么写查询函数了

例如:

 @Query("{\"bool\" : {\"must\" : {\"term\" : {\"message\" : \"?0\"}}}}")
    Page<Book> findByMessage(String message, Pageable pageable);

我如何为_all查询编写查找函数

spring-data-elasticsearch
1个回答
3
投票

像这样尝试一下,@query注释不是强制性的:-

有查询:-

@Query("{\"bool\" : {\"must\" : [ {\"match\" : {\"?0\" : \"?1\"}} ]}}")
Page<MyDoc> getbyAll(String a, String b, Pageable pageable);

int aPageReuestcount = (int) myRepositiry.count();
Page<MyDoc> aData = myRepositiry.getbyAll("_all", "HelloWorld", new PageRequest(0, aPageReuestcount));
List<MyDoc> aDataList = aData.getContent();

没有查询:-

@Override
public List<MyDoc> getDatawithAllFields(String a) {
    NativeSearchQueryBuilder aNativeSearchQueryBuilder = new NativeSearchQueryBuilder();
    aNativeSearchQueryBuilder.withIndices(indexName).withTypes(type);
    final BoolQueryBuilder aQuery = new BoolQueryBuilder();

    aQuery.must(QueryBuilders.matchQuery("_all",  a));

    NativeSearchQuery nativeSearchQuery = aNativeSearchQueryBuilder.withQuery(aQuery).build();
    List<MyDoc> aData = elasticsearchTemplate.queryForList(nativeSearchQuery, MyDoc.class);
    return aData;
}

进口:-

import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;

按照此链接 .

© www.soinside.com 2019 - 2024. All rights reserved.