use of org.elasticsearch.mapping.SourceFetchContext in project alien4cloud by alien4cloud.
the class ESGenericSearchDAO method findByIdsWithContext.
@Override
public <T> List<T> findByIdsWithContext(Class<T> clazz, String fetchContext, String... ids) {
// get the fetch context for the given type and apply it to the search
List<String> includes = new ArrayList<String>();
List<String> excludes = new ArrayList<String>();
SourceFetchContext sourceFetchContext = getMappingBuilder().getFetchSource(clazz.getName(), fetchContext);
if (sourceFetchContext != null) {
includes.addAll(sourceFetchContext.getIncludes());
excludes.addAll(sourceFetchContext.getExcludes());
} else {
getLog().warn("Unable to find fetch context <" + fetchContext + "> for class <" + clazz.getName() + ">. It will be ignored.");
}
String[] inc = includes.isEmpty() ? null : includes.toArray(new String[includes.size()]);
String[] exc = excludes.isEmpty() ? null : excludes.toArray(new String[excludes.size()]);
// TODO: correctly manage "from" and "size"
SearchRequestBuilder searchRequestBuilder = getClient().prepareSearch(getIndexForType(clazz)).setQuery(QueryBuilders.idsQuery(MappingBuilder.indexTypeFromClass(clazz)).ids(ids)).setFetchSource(inc, exc).setSize(20);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
return toGetListOfData(searchResponse, clazz);
}
Aggregations