How to search inside all types in elastic index using spring data elasticsearch

一笑奈何 提交于 2019-12-08 08:14:35

问题


I'm building a search application in which I will have to search inside all types in specified index and specific type in specified index. Am using spring data elasticsearch as my java client for elasticsearch. But am getting no hits in the case where I have to search whole of the index(all types).

Code snippets used for search :-

Whole index(Returns 0 hits) :-

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

Inside specific type :-

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

And am using SearchResultMapper for building highlighted results.

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

And my model class is like this :-

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

Am dummying indexName and typeName parameters here. Is that the issue ? Or am I missing anything. Please help

来源:https://stackoverflow.com/questions/39361746/how-to-search-inside-all-types-in-elastic-index-using-spring-data-elasticsearch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!