如何使用spring data elasticsearch搜索弹性索引中的所有类型

时间:2016-09-07 05:24:12

标签: elasticsearch spring-data-elasticsearch

我正在构建一个搜索应用程序,我将在其中搜索指定索引中的所有类型以及指定索引中的特定类型。我使用spring data elasticsearch作为我的弹性搜索的java客户端。但是在我必须搜索整个索引(所有类型)的情况下,我没有得到任何命中。

用于搜索的代码段: -

整个索引(返回0次点击): -

 SearchQuery searchQuery = new NativeSearchQueryBuilder()
                            .withIndices(<index_name>)
                            .withQuery(finalQuery)
                            .withHighlightFields(field).build();

内部特定类型: -

SearchQuery searchQuery = new NativeSearchQueryBuilder()
                        .withIndices(<index_name>)
                        .withTypes(<type_name>).withQuery(finalQuery)
                        .withHighlightFields(field).build();

我正在使用SearchResultMapper来构建突出显示的结果。

elasticsearchTemplate.queryForPage(searchQuery, DocumentModel.class, new SearchResultMapper() {
.........
}

我的模型类是这样的: -

   @Document(indexName = "myindex",typeName="myType", createIndex = true)
    public class DocumentModel {
     ............
    }

这里是dummying indexName和typeName参数。这是问题吗?或者我错过了什么。请帮忙

0 个答案:

没有答案