@Query match _all function

时间:2017-04-13 04:42:52

标签: spring-data-elasticsearch

我是Spring数据弹性搜索的新手,我想推测这个休息查询

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查询编写查找函数

1 个答案:

答案 0 :(得分: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;

按照link