问题
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