mirror of
https://github.com/spring-projects/spring-data-elasticsearch.git
synced 2025-06-22 12:02:10 +00:00
DATAES-180 - clean up
This commit is contained in:
parent
fd06f8efd7
commit
6ffac62b3e
@ -35,12 +35,15 @@ import org.elasticsearch.action.get.MultiGetResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHitField;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.ScriptedField;
|
||||
import org.springframework.data.elasticsearch.core.domain.impl.AggregatedPageImpl;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentProperty;
|
||||
import org.springframework.data.mapping.PersistentProperty;
|
||||
@ -52,6 +55,8 @@ import org.springframework.data.mapping.context.MappingContext;
|
||||
*/
|
||||
public class DefaultResultMapper extends AbstractResultMapper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DefaultResultMapper.class);
|
||||
|
||||
private MappingContext<? extends ElasticsearchPersistentEntity<?>, ElasticsearchPersistentProperty> mappingContext;
|
||||
|
||||
public DefaultResultMapper() {
|
||||
@ -75,7 +80,7 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
long totalHits = response.getHits().totalHits();
|
||||
List<T> results = new ArrayList<T>();
|
||||
for (SearchHit hit : response.getHits()) {
|
||||
@ -180,7 +185,7 @@ public class DefaultResultMapper extends AbstractResultMapper {
|
||||
try {
|
||||
setter.invoke(result, id);
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
LOG.error("Unable to set entity Id", t);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,8 +81,11 @@ import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.annotations.Mapping;
|
||||
import org.springframework.data.elasticsearch.annotations.Setting;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity;
|
||||
import org.springframework.data.elasticsearch.core.mapping.SimpleElasticsearchMappingContext;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
@ -261,12 +264,12 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Page<T> queryForPage(SearchQuery query, Class<T> clazz) {
|
||||
public <T> AggregatedPage<T> queryForPage(SearchQuery query, Class<T> clazz) {
|
||||
return queryForPage(query, clazz, resultsMapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Page<T> queryForPage(SearchQuery query, Class<T> clazz, SearchResultMapper mapper) {
|
||||
public <T> AggregatedPage<T> queryForPage(SearchQuery query, Class<T> clazz, SearchResultMapper mapper) {
|
||||
SearchResponse response = doSearch(prepareSearch(query, clazz), query);
|
||||
return mapper.mapResults(response, clazz, query.getPageable());
|
||||
}
|
||||
@ -410,6 +413,11 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
}
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException("remove");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -664,14 +672,14 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
while (hasRecords) {
|
||||
Page<String> page = scroll(scrollId, scrollTimeInMillis, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<String> result = new ArrayList<String>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
String id = searchHit.getId();
|
||||
result.add(id);
|
||||
}
|
||||
if (result.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) result);
|
||||
return new AggregatedPageImpl<T>((List<T>) result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -880,6 +888,12 @@ public class ElasticsearchTemplate implements ElasticsearchOperations, Applicati
|
||||
searchRequest.addAggregation(aggregationBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
if (!isEmpty(searchQuery.getFacets())) {
|
||||
for (FacetRequest aggregatedFacet : searchQuery.getFacets()) {
|
||||
searchRequest.addAggregation(aggregatedFacet.getFacet());
|
||||
}
|
||||
}
|
||||
return getSearchResponse(searchRequest.setQuery(searchQuery.getQuery()).execute());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetResult;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Jonathan Yan
|
||||
*/
|
||||
@Deprecated
|
||||
public interface FacetedPage<T> extends Page<T> {
|
||||
|
||||
boolean hasFacets();
|
||||
|
||||
List<FacetResult> getFacets();
|
||||
|
||||
FacetResult getFacet(String name);
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
|
||||
import org.elasticsearch.search.aggregations.bucket.range.Range;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.aggregations.metrics.stats.Stats;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetResult;
|
||||
import org.springframework.data.elasticsearch.core.facet.result.*;
|
||||
|
||||
/**
|
||||
* Container for query result and facet results
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Jonathan Yan
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class FacetedPageImpl<T> extends PageImpl<T> implements FacetedPage<T>, AggregatedPage<T> {
|
||||
|
||||
private List<FacetResult> facets;
|
||||
private Map<String, FacetResult> mapOfFacets = new HashMap<String, FacetResult>();
|
||||
|
||||
public FacetedPageImpl(List<T> content) {
|
||||
super(content);
|
||||
}
|
||||
|
||||
public FacetedPageImpl(List<T> content, Pageable pageable, long total) {
|
||||
super(content, pageable, total);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFacets() {
|
||||
processAggregations();
|
||||
return facets != null && facets.size() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FacetResult> getFacets() {
|
||||
processAggregations();
|
||||
return facets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FacetResult getFacet(String name) {
|
||||
processAggregations();
|
||||
return mapOfFacets.get(name);
|
||||
}
|
||||
|
||||
private void addFacet(FacetResult facetResult) {
|
||||
facets.add(facetResult);
|
||||
mapOfFacets.put(facetResult.getName(), facetResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lazy conversion from aggregation to old facets
|
||||
*/
|
||||
private void processAggregations() {
|
||||
if (facets == null) {
|
||||
facets = new ArrayList<FacetResult>();
|
||||
for (Aggregation agg : getAggregations()) {
|
||||
if (agg instanceof Terms) {
|
||||
List<Term> terms = new ArrayList<Term>();
|
||||
for (Terms.Bucket t : ((Terms) agg).getBuckets()) {
|
||||
terms.add(new Term(t.getKeyAsString(), t.getDocCount()));
|
||||
}
|
||||
addFacet(new TermResult(agg.getName(), terms, terms.size(), ((Terms) agg).getSumOfOtherDocCounts(), -1));
|
||||
}
|
||||
if (agg instanceof Range) {
|
||||
List<? extends Range.Bucket> buckets = ((Range) agg).getBuckets();
|
||||
List<org.springframework.data.elasticsearch.core.facet.result.Range> ranges = new ArrayList<org.springframework.data.elasticsearch.core.facet.result.Range>();
|
||||
for (Range.Bucket b : buckets) {
|
||||
ranges.add(new org.springframework.data.elasticsearch.core.facet.result.Range((Double) b.getFrom(), (Double) b.getTo(), b.getDocCount(), 0, 0, 0, 0));
|
||||
}
|
||||
addFacet(new RangeResult(agg.getName(), ranges));
|
||||
}
|
||||
if (agg instanceof Stats) {
|
||||
Stats stats = (Stats) agg;
|
||||
addFacet(new StatisticalResult(agg.getName(), stats.getCount(), stats.getMax(), stats.getMin(), stats.getAvg(), -1, -1, stats.getSum(), -1));
|
||||
}
|
||||
if (agg instanceof Histogram) {
|
||||
List<IntervalUnit> intervals = new ArrayList<IntervalUnit>();
|
||||
for (Histogram.Bucket h : ((Histogram) agg).getBuckets()) {
|
||||
new IntervalUnit((Long) h.getKey(), h.getDocCount(), h.getDocCount(), -1, -1, -1, -1);
|
||||
}
|
||||
addFacet(new HistogramResult(agg.getName(), intervals));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -16,9 +16,8 @@
|
||||
package org.springframework.data.elasticsearch.core;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.domain.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
@ -26,5 +25,5 @@ import org.springframework.data.elasticsearch.core.domain.AggregatedPage;
|
||||
*/
|
||||
public interface SearchResultMapper {
|
||||
|
||||
<T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable);
|
||||
<T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable);
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package org.springframework.data.elasticsearch.core.domain;
|
||||
package org.springframework.data.elasticsearch.core.aggregation;
|
||||
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.springframework.data.elasticsearch.core.FacetedPage;
|
||||
|
||||
/**
|
||||
* @author Petar Tahchiev
|
||||
*/
|
||||
public interface AggregatedPage<T> {
|
||||
public interface AggregatedPage<T> extends FacetedPage<T> {
|
||||
|
||||
boolean hasAggregations();
|
||||
|
@ -1,4 +1,4 @@
|
||||
package org.springframework.data.elasticsearch.core.domain.impl;
|
||||
package org.springframework.data.elasticsearch.core.aggregation.impl;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -6,14 +6,16 @@ import java.util.Map;
|
||||
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.domain.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.FacetedPageImpl;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
|
||||
/**
|
||||
* @author Petar Tahchiev
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
public class AggregatedPageImpl<T> extends PageImpl<T> implements AggregatedPage<T> {
|
||||
public class AggregatedPageImpl<T> extends FacetedPageImpl<T> implements AggregatedPage<T> {
|
||||
|
||||
private Aggregations aggregations;
|
||||
private Map<String, Aggregation> mapOfAggregations = new HashMap<String, Aggregation>();
|
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractFacetRequest implements FacetRequest {
|
||||
|
||||
private String name;
|
||||
private boolean applyQueryFilter;
|
||||
|
||||
public AbstractFacetRequest(String name) {
|
||||
Assert.hasText(name, "Facet can't be null or empty !!!");
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
protected String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setApplyQueryFilter(boolean applyQueryFilter) {
|
||||
this.applyQueryFilter = applyQueryFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyQueryFilter() {
|
||||
return applyQueryFilter;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Jonathan Yan
|
||||
*/
|
||||
@Deprecated
|
||||
public class AbstractFacetResult implements FacetResult {
|
||||
|
||||
private final String name;
|
||||
private final FacetType type;
|
||||
|
||||
protected AbstractFacetResult(String name, FacetType type) {
|
||||
Assert.hasText(name, "Facet name can't be null and should have a value");
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FacetType getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
///*
|
||||
// * Copyright 2014 the original author or authors.
|
||||
// *
|
||||
// * Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// * you may not use this file except in compliance with the License.
|
||||
// * You may obtain a copy of the License at
|
||||
// *
|
||||
// * http://www.apache.org/licenses/LICENSE-2.0
|
||||
// *
|
||||
// * Unless required by applicable law or agreed to in writing, software
|
||||
// * distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// * See the License for the specific language governing permissions and
|
||||
// * limitations under the License.
|
||||
// */
|
||||
//package org.springframework.data.elasticsearch.core.facet;
|
||||
//
|
||||
//import java.util.ArrayList;
|
||||
//import java.util.List;
|
||||
//
|
||||
//import org.elasticsearch.search.facet.Facet;
|
||||
//import org.elasticsearch.search.facet.histogram.HistogramFacet;
|
||||
//import org.elasticsearch.search.facet.range.RangeFacet;
|
||||
//import org.elasticsearch.search.facet.statistical.StatisticalFacet;
|
||||
//import org.elasticsearch.search.facet.terms.TermsFacet;
|
||||
//import org.springframework.data.elasticsearch.core.facet.result.*;
|
||||
//
|
||||
///**
|
||||
// * @author Artur Konczak
|
||||
// * @author Petar Tahchiev
|
||||
// */
|
||||
//public class DefaultFacetMapper {
|
||||
//
|
||||
// public static FacetResult parse(Facet facet) {
|
||||
// if (facet instanceof TermsFacet) {
|
||||
// return parseTerm((TermsFacet) facet);
|
||||
// }
|
||||
//
|
||||
// if (facet instanceof RangeFacet) {
|
||||
// return parseRange((RangeFacet) facet);
|
||||
// }
|
||||
//
|
||||
// if (facet instanceof StatisticalFacet) {
|
||||
// return parseStatistical((StatisticalFacet) facet);
|
||||
// }
|
||||
//
|
||||
// if (facet instanceof HistogramFacet) {
|
||||
// return parseHistogram((HistogramFacet) facet);
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// private static FacetResult parseTerm(TermsFacet facet) {
|
||||
// List<Term> entries = new ArrayList<Term>();
|
||||
// for (TermsFacet.Entry entry : facet.getEntries()) {
|
||||
// entries.add(new Term(entry.getTerm().toString(), entry.getCount()));
|
||||
// }
|
||||
// return new TermResult(facet.getName(), entries, facet.getTotalCount(), facet.getOtherCount(), facet.getMissingCount());
|
||||
// }
|
||||
//
|
||||
// private static FacetResult parseRange(RangeFacet facet) {
|
||||
// List<Range> entries = new ArrayList<Range>();
|
||||
// for (RangeFacet.Entry entry : facet.getEntries()) {
|
||||
// entries.add(new Range(entry.getFrom() == Double.NEGATIVE_INFINITY ? null : entry.getFrom(), entry.getTo() == Double.POSITIVE_INFINITY ? null : entry.getTo(), entry.getCount(), entry.getTotal(), entry.getTotalCount(), entry.getMin(), entry.getMax()));
|
||||
// }
|
||||
// return new RangeResult(facet.getName(), entries);
|
||||
// }
|
||||
//
|
||||
// private static FacetResult parseStatistical(StatisticalFacet facet) {
|
||||
// return new StatisticalResult(facet.getName(), facet.getCount(), facet.getMax(), facet.getMin(), facet.getMean(), facet.getStdDeviation(), facet.getSumOfSquares(), facet.getTotal(), facet.getVariance());
|
||||
// }
|
||||
//
|
||||
// private static FacetResult parseHistogram(HistogramFacet facet) {
|
||||
// List<IntervalUnit> entries = new ArrayList<IntervalUnit>();
|
||||
// for (HistogramFacet.Entry entry : facet.getEntries()) {
|
||||
// entries.add(new IntervalUnit(entry.getKey(), entry.getCount(), entry.getTotalCount(), entry.getTotal(), entry.getMean(), entry.getMin(), entry.getMax()));
|
||||
// }
|
||||
// return new HistogramResult(facet.getName(), entries);
|
||||
// }
|
||||
//}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet;
|
||||
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
|
||||
/**
|
||||
* @author Artur Koczak
|
||||
*/
|
||||
@Deprecated
|
||||
public interface FacetRequest {
|
||||
|
||||
public static final String FIELD_UNTOUCHED = "untouched";
|
||||
public static final String FIELD_SORT = "sort";
|
||||
|
||||
AbstractAggregationBuilder getFacet();
|
||||
|
||||
boolean applyQueryFilter();
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet;
|
||||
|
||||
/**
|
||||
* Generic interface for all facets
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Jonathan Yan
|
||||
*/
|
||||
@Deprecated
|
||||
public interface FacetResult {
|
||||
|
||||
String getName();
|
||||
|
||||
FacetType getType();
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Petar Tahchiev
|
||||
*/
|
||||
@Deprecated
|
||||
public enum FacetType {
|
||||
|
||||
term, range, histogram, statistical
|
||||
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Deprecated
|
||||
public class HistogramFacetRequest extends AbstractFacetRequest {
|
||||
|
||||
private String field;
|
||||
private long interval;
|
||||
private DateHistogramInterval timeUnit;
|
||||
|
||||
public HistogramFacetRequest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void setField(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public void setInterval(long interval) {
|
||||
this.interval = interval;
|
||||
}
|
||||
|
||||
public void setTimeUnit(DateHistogramInterval timeUnit) {
|
||||
this.timeUnit = timeUnit;
|
||||
}
|
||||
|
||||
public AbstractAggregationBuilder getFacet() {
|
||||
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
||||
Assert.isTrue(StringUtils.isNotBlank(field), "Please select field on which to build the facet !!!");
|
||||
Assert.isTrue(interval > 0, "Please provide interval as positive value greater them zero !!!");
|
||||
|
||||
DateHistogramBuilder dateHistogramBuilder = AggregationBuilders.dateHistogram(getName());
|
||||
dateHistogramBuilder.field(field);
|
||||
|
||||
if (timeUnit != null) {
|
||||
dateHistogramBuilder.interval(timeUnit);
|
||||
} else {
|
||||
dateHistogramBuilder.interval(interval);
|
||||
}
|
||||
|
||||
return dateHistogramBuilder;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@Deprecated
|
||||
public class HistogramFacetRequestBuilder {
|
||||
|
||||
HistogramFacetRequest result;
|
||||
|
||||
public HistogramFacetRequestBuilder(String name) {
|
||||
result = new HistogramFacetRequest(name);
|
||||
}
|
||||
|
||||
public HistogramFacetRequestBuilder field(String field) {
|
||||
result.setField(field);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HistogramFacetRequestBuilder interval(long interval) {
|
||||
result.setInterval(interval);
|
||||
return this;
|
||||
}
|
||||
|
||||
public HistogramFacetRequestBuilder timeUnit(DateHistogramInterval timeUnit) {
|
||||
result.setTimeUnit(timeUnit);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FacetRequest build() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public HistogramFacetRequestBuilder applyQueryFilter() {
|
||||
result.setApplyQueryFilter(true);
|
||||
return this;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Deprecated
|
||||
public class NativeFacetRequest implements FacetRequest {
|
||||
|
||||
public NativeFacetRequest() {
|
||||
throw new UnsupportedOperationException("Native Facet are not supported in Elasticsearch 2.x - use Aggregation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractAggregationBuilder getFacet() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applyQueryFilter() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.range.RangeBuilder;
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* Range facet for numeric fields
|
||||
*
|
||||
* @author Artur Konczak
|
||||
* @author Akos Bordas
|
||||
*/
|
||||
@Deprecated
|
||||
public class RangeFacetRequest extends AbstractFacetRequest {
|
||||
|
||||
private String field;
|
||||
private String keyField;
|
||||
private String valueField;
|
||||
|
||||
private List<Entry> entries = new ArrayList<Entry>();
|
||||
|
||||
public RangeFacetRequest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void setField(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public void setFields(String keyField, String valueField) {
|
||||
throw new UnsupportedOperationException("Native Facet are not supported in Elasticsearch 2.x - use Aggregation");
|
||||
}
|
||||
|
||||
public void range(Double from, Double to) {
|
||||
entries.add(new DoubleEntry(from, to));
|
||||
}
|
||||
|
||||
public void range(String from, String to) {
|
||||
throw new UnsupportedOperationException("Native Facet are not supported in Elasticsearch 2.x - use Aggregation");
|
||||
}
|
||||
|
||||
public void addRange(Double from, Double to) {
|
||||
entries.add(new DoubleEntry(from, to));
|
||||
}
|
||||
|
||||
public void addRange(String from, String to) {
|
||||
throw new UnsupportedOperationException("Native Facet are not supported in Elasticsearch 2.x - use Aggregation");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractAggregationBuilder getFacet() {
|
||||
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
||||
|
||||
RangeBuilder rangeBuilder = AggregationBuilders.range(getName());
|
||||
rangeBuilder.field(field);
|
||||
|
||||
for (Entry entry : entries) {
|
||||
DoubleEntry doubleEntry = (DoubleEntry) entry;
|
||||
rangeBuilder.addRange(validateValue(doubleEntry.getFrom(), Double.NEGATIVE_INFINITY), validateValue(doubleEntry.getTo(), Double.POSITIVE_INFINITY));
|
||||
}
|
||||
|
||||
return rangeBuilder;
|
||||
}
|
||||
|
||||
private double validateValue(Double value, double defaultValue) {
|
||||
return value == null ? defaultValue : value;
|
||||
}
|
||||
|
||||
static class DoubleEntry extends Entry<Double> {
|
||||
|
||||
DoubleEntry(Double from, Double to) {
|
||||
super(from, to);
|
||||
}
|
||||
}
|
||||
|
||||
static class StringEntry extends Entry<String> {
|
||||
|
||||
StringEntry(String from, String to) {
|
||||
super(from, to);
|
||||
}
|
||||
}
|
||||
|
||||
static class Entry<T> {
|
||||
|
||||
T from;
|
||||
T to;
|
||||
|
||||
Entry(T from, T to) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
public T getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public T getTo() {
|
||||
return to;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
|
||||
|
||||
/**
|
||||
* Basic range facet
|
||||
*
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@Deprecated
|
||||
public class RangeFacetRequestBuilder {
|
||||
|
||||
RangeFacetRequest result;
|
||||
|
||||
public RangeFacetRequestBuilder(String name) {
|
||||
result = new RangeFacetRequest(name);
|
||||
}
|
||||
|
||||
public RangeFacetRequestBuilder field(String field) {
|
||||
result.setField(field);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RangeFacetRequestBuilder fields(String keyField, String valueField) {
|
||||
result.setFields(keyField, valueField);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public RangeFacetRequestBuilder range(double from, double to) {
|
||||
result.range(from, to);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RangeFacetRequestBuilder range(String from, String to) {
|
||||
result.range(from, to);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RangeFacetRequestBuilder from(double from) {
|
||||
result.range(from, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RangeFacetRequestBuilder to(double to) {
|
||||
result.range(null, to);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RangeFacetRequestBuilder from(String from) {
|
||||
result.range(from, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RangeFacetRequestBuilder to(String to) {
|
||||
result.range(null, to);
|
||||
return this;
|
||||
}
|
||||
|
||||
public RangeFacetRequestBuilder applyQueryFilter() {
|
||||
result.setApplyQueryFilter(true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FacetRequest build() {
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* @author Petar Tahchiev
|
||||
*/
|
||||
@Deprecated
|
||||
public class StatisticalFacetRequest extends AbstractFacetRequest {
|
||||
|
||||
private String field;
|
||||
|
||||
private String[] fields;
|
||||
|
||||
public StatisticalFacetRequest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void setField(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public void setFields(String... fields) {
|
||||
throw new UnsupportedOperationException("Native Facet are not supported in Elasticsearch 2.x - use Aggregation");
|
||||
}
|
||||
|
||||
public AbstractAggregationBuilder getFacet() {
|
||||
Assert.notNull(getName(), "Facet name can't be a null !!!");
|
||||
Assert.isTrue(StringUtils.isNotBlank(field) && fields == null, "Please select field or fields on which to build the facets !!!");
|
||||
return AggregationBuilders.stats(getName()).field(field);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
|
||||
|
||||
/**
|
||||
* @author Petar Tahchiev
|
||||
*/
|
||||
@Deprecated
|
||||
public class StatisticalFacetRequestBuilder {
|
||||
|
||||
StatisticalFacetRequest result;
|
||||
|
||||
public StatisticalFacetRequestBuilder(String name) {
|
||||
result = new StatisticalFacetRequest(name);
|
||||
}
|
||||
|
||||
public StatisticalFacetRequestBuilder field(String field) {
|
||||
result.setField(field);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StatisticalFacetRequestBuilder fields(String... fields) {
|
||||
result.setFields(fields);
|
||||
return this;
|
||||
}
|
||||
|
||||
public StatisticalFacetRequestBuilder applyQueryFilter() {
|
||||
result.setApplyQueryFilter(true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FacetRequest build() {
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
* @author Mohsin Husen
|
||||
*/
|
||||
@Deprecated
|
||||
public enum TermFacetOrder {
|
||||
|
||||
ascTerm, descTerm, ascCount, descCount;
|
||||
|
||||
}
|
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.TermsBuilder;
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetRequest;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* Term facet
|
||||
*
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@Deprecated
|
||||
public class TermFacetRequest extends AbstractFacetRequest {
|
||||
|
||||
private String[] fields;
|
||||
private String[] excludeTerms;
|
||||
private int size = 10;
|
||||
private TermFacetOrder order = TermFacetOrder.descCount;
|
||||
private boolean allTerms = false;
|
||||
private String regex = null;
|
||||
|
||||
public TermFacetRequest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void setFields(String... fields) {
|
||||
Assert.isTrue(ArrayUtils.isNotEmpty(fields), "Term agg need one field");
|
||||
Assert.isTrue(ArrayUtils.getLength(fields) == 1, "Term agg need one field");
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
public void setSize(int size) {
|
||||
Assert.isTrue(size >= 0, "Size should be bigger then zero !!!");
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
public void setOrder(TermFacetOrder order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public void setExcludeTerms(String... excludeTerms) {
|
||||
this.excludeTerms = excludeTerms;
|
||||
}
|
||||
|
||||
public void setAllTerms(boolean allTerms) {
|
||||
this.allTerms = allTerms;
|
||||
}
|
||||
|
||||
public void setRegex(String regex) {
|
||||
this.regex = regex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractAggregationBuilder getFacet() {
|
||||
Assert.notEmpty(fields, "Please select at last one field !!!");
|
||||
TermsBuilder termsBuilder = AggregationBuilders.terms(getName()).field(fields[0]).size(this.size);
|
||||
|
||||
switch (order) {
|
||||
case descTerm:
|
||||
termsBuilder.order(Terms.Order.term(false));
|
||||
break;
|
||||
case ascTerm:
|
||||
termsBuilder.order(Terms.Order.term(true));
|
||||
break;
|
||||
case ascCount:
|
||||
termsBuilder.order(Terms.Order.count(true));
|
||||
break;
|
||||
default:
|
||||
termsBuilder.order(Terms.Order.count(false));
|
||||
}
|
||||
if (ArrayUtils.isNotEmpty(excludeTerms)) {
|
||||
termsBuilder.exclude(excludeTerms);
|
||||
}
|
||||
|
||||
if (allTerms) {
|
||||
termsBuilder.size(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(regex)) {
|
||||
termsBuilder.include(regex);
|
||||
}
|
||||
|
||||
return termsBuilder;
|
||||
}
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.elasticsearch.core.facet.request;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
|
||||
/**
|
||||
* Basic term facet
|
||||
*
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@Deprecated
|
||||
public class TermFacetRequestBuilder {
|
||||
|
||||
private TermFacetRequest result;
|
||||
|
||||
public TermFacetRequestBuilder(String name) {
|
||||
result = new TermFacetRequest(name);
|
||||
}
|
||||
|
||||
public TermFacetRequestBuilder fields(String... fields) {
|
||||
result.setFields(fields);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TermFacetRequestBuilder size(int size) {
|
||||
result.setSize(size);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TermFacetRequestBuilder excludeTerms(String... terms) {
|
||||
result.setExcludeTerms(terms);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TermFacetRequestBuilder allTerms() {
|
||||
result.setAllTerms(true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TermFacetRequestBuilder regex(String regex) {
|
||||
result.setRegex(regex);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TermFacetRequestBuilder ascTerm() {
|
||||
result.setOrder(TermFacetOrder.ascTerm);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TermFacetRequestBuilder descTerm() {
|
||||
result.setOrder(TermFacetOrder.descTerm);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TermFacetRequestBuilder ascCount() {
|
||||
result.setOrder(TermFacetOrder.ascCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TermFacetRequestBuilder descCount() {
|
||||
result.setOrder(TermFacetOrder.descCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TermFacetRequestBuilder applyQueryFilter() {
|
||||
result.setApplyQueryFilter(true);
|
||||
return this;
|
||||
}
|
||||
|
||||
public FacetRequest build() {
|
||||
return result;
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet.result;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetResult;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetType;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
*/
|
||||
@Deprecated
|
||||
public class HistogramResult extends AbstractFacetResult {
|
||||
|
||||
private List<IntervalUnit> terms;
|
||||
|
||||
public HistogramResult(String name, List<IntervalUnit> terms) {
|
||||
super(name, FacetType.term);
|
||||
this.terms = terms;
|
||||
}
|
||||
|
||||
public List<IntervalUnit> getIntervalUnit() {
|
||||
return terms;
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet.result;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Single term
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Jonathan Yan
|
||||
*/
|
||||
@Deprecated
|
||||
public class IntervalUnit {
|
||||
|
||||
private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
|
||||
long key;
|
||||
long count;
|
||||
long totalCount;
|
||||
double total;
|
||||
double mean;
|
||||
double min;
|
||||
double max;
|
||||
|
||||
public IntervalUnit(long key, long count, long totalCount, double total, double mean, double min, double max) {
|
||||
this.key = key;
|
||||
this.count = count;
|
||||
this.totalCount = totalCount;
|
||||
this.total = total;
|
||||
this.mean = mean;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public long getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public long getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public double getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public double getMean() {
|
||||
return mean;
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public double getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "IntervalUnit{" +
|
||||
"key=" + format.format(new Date(key)) +
|
||||
", count=" + count +
|
||||
", totalCount=" + totalCount +
|
||||
", total=" + total +
|
||||
", mean=" + mean +
|
||||
", min=" + min +
|
||||
", max=" + max +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet.result;
|
||||
|
||||
/**
|
||||
* Single range
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Jonathan Yan
|
||||
*/
|
||||
@Deprecated
|
||||
public class Range {
|
||||
|
||||
private Double from;
|
||||
private Double to;
|
||||
private long count;
|
||||
private double total;
|
||||
private double totalCount;
|
||||
private double min = Double.POSITIVE_INFINITY;
|
||||
private double max = Double.NEGATIVE_INFINITY;
|
||||
|
||||
public Range(Double from, Double to, long count, double total, double totalCount, double min, double max) {
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
this.count = count;
|
||||
this.total = total;
|
||||
this.totalCount = totalCount;
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public Double getFrom() {
|
||||
return from;
|
||||
}
|
||||
|
||||
public Double getTo() {
|
||||
return to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return number of documents in range
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public double getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public double getTotalCount() {
|
||||
return totalCount;
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public double getMax() {
|
||||
return max;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet.result;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetResult;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetType;
|
||||
|
||||
/**
|
||||
* Basic term facet result
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Jonathan Yan
|
||||
*/
|
||||
@Deprecated
|
||||
public class RangeResult extends AbstractFacetResult {
|
||||
|
||||
private List<Range> ranges;
|
||||
|
||||
public RangeResult(String name, List<Range> ranges) {
|
||||
super(name, FacetType.range);
|
||||
this.ranges = ranges;
|
||||
}
|
||||
|
||||
public List<Range> getRanges() {
|
||||
return ranges;
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet.result;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetResult;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetType;
|
||||
|
||||
/**
|
||||
* @author Petar Tahchiev
|
||||
*/
|
||||
@Deprecated
|
||||
public class StatisticalResult extends AbstractFacetResult {
|
||||
|
||||
private long count;
|
||||
|
||||
private double max;
|
||||
|
||||
private double min;
|
||||
|
||||
private double mean;
|
||||
|
||||
private double stdDeviation;
|
||||
|
||||
private double sumOfSquares;
|
||||
|
||||
private double total;
|
||||
|
||||
private double variance;
|
||||
|
||||
public StatisticalResult(String name, long count, double max, double min, double mean, double stdDeviation, double sumOfSquares, double total, double variance) {
|
||||
super(name, FacetType.statistical);
|
||||
this.count = count;
|
||||
this.max = max;
|
||||
this.min = min;
|
||||
this.mean = mean;
|
||||
this.stdDeviation = stdDeviation;
|
||||
this.sumOfSquares = sumOfSquares;
|
||||
this.total = total;
|
||||
this.variance = variance;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public double getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public double getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public double getMean() {
|
||||
return mean;
|
||||
}
|
||||
|
||||
public double getStdDeviation() {
|
||||
return stdDeviation;
|
||||
}
|
||||
|
||||
public double getSumOfSquares() {
|
||||
return sumOfSquares;
|
||||
}
|
||||
|
||||
public double getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public double getVariance() {
|
||||
return variance;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet.result;
|
||||
|
||||
/**
|
||||
* Single term
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Jonathan Yan
|
||||
*/
|
||||
@Deprecated
|
||||
public class Term {
|
||||
|
||||
private String term;
|
||||
private long count;
|
||||
|
||||
public Term(String term, long count) {
|
||||
this.term = term;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getTerm() {
|
||||
return term;
|
||||
}
|
||||
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.elasticsearch.core.facet.result;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.elasticsearch.core.facet.AbstractFacetResult;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetType;
|
||||
|
||||
/**
|
||||
* Basic term facet result
|
||||
*
|
||||
* @author Rizwan Idrees
|
||||
* @author Mohsin Husen
|
||||
* @author Artur Konczak
|
||||
* @author Jonathan Yan
|
||||
* @author Matija Obreza
|
||||
*/
|
||||
@Deprecated
|
||||
public class TermResult extends AbstractFacetResult {
|
||||
|
||||
private List<Term> terms;
|
||||
private long total;
|
||||
private long other;
|
||||
private long missing;
|
||||
|
||||
public TermResult(String name, List<Term> terms, long total, long other, long missing) {
|
||||
super(name, FacetType.term);
|
||||
this.terms = terms;
|
||||
this.total = total;
|
||||
this.other = other;
|
||||
this.missing = missing;
|
||||
}
|
||||
|
||||
public List<Term> getTerms() {
|
||||
return terms;
|
||||
}
|
||||
|
||||
public long getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public long getOther() {
|
||||
return other;
|
||||
}
|
||||
|
||||
public long getMissing() {
|
||||
return missing;
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@ -38,7 +39,7 @@ public class NativeSearchQuery extends AbstractQuery implements SearchQuery {
|
||||
private QueryBuilder filter;
|
||||
private List<SortBuilder> sorts;
|
||||
private final List<ScriptField> scriptFields = new ArrayList<ScriptField>();
|
||||
/*private List<FacetRequest> facets;*/
|
||||
private List<FacetRequest> facets;
|
||||
private List<AbstractAggregationBuilder> aggregations;
|
||||
private HighlightBuilder.Field[] highlightFields;
|
||||
private List<IndexBoost> indicesBoost;
|
||||
@ -94,7 +95,7 @@ public class NativeSearchQuery extends AbstractQuery implements SearchQuery {
|
||||
scriptFields.addAll(Arrays.asList(scriptField));
|
||||
}
|
||||
|
||||
/* public void addFacet(FacetRequest facetRequest) {
|
||||
public void addFacet(FacetRequest facetRequest) {
|
||||
if (facets == null) {
|
||||
facets = new ArrayList<FacetRequest>();
|
||||
}
|
||||
@ -108,7 +109,7 @@ public class NativeSearchQuery extends AbstractQuery implements SearchQuery {
|
||||
@Override
|
||||
public List<FacetRequest> getFacets() {
|
||||
return facets;
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractAggregationBuilder> getAggregations() {
|
||||
|
@ -25,6 +25,7 @@ import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
|
||||
/**
|
||||
* NativeSearchQuery
|
||||
@ -40,6 +41,7 @@ public class NativeSearchQueryBuilder {
|
||||
private QueryBuilder filterBuilder;
|
||||
private List<ScriptField> scriptFields = new ArrayList<ScriptField>();
|
||||
private List<SortBuilder> sortBuilders = new ArrayList<SortBuilder>();
|
||||
private List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
|
||||
private List<AbstractAggregationBuilder> aggregationBuilders = new ArrayList<AbstractAggregationBuilder>();
|
||||
private HighlightBuilder.Field[] highlightFields;
|
||||
private Pageable pageable;
|
||||
@ -78,10 +80,10 @@ public class NativeSearchQueryBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/* public NativeSearchQueryBuilder withFacet(FacetRequest facetRequest) {
|
||||
public NativeSearchQueryBuilder withFacet(FacetRequest facetRequest) {
|
||||
facetRequests.add(facetRequest);
|
||||
return this;
|
||||
}*/
|
||||
}
|
||||
|
||||
public NativeSearchQueryBuilder withHighlightFields(HighlightBuilder.Field... highlightFields) {
|
||||
this.highlightFields = highlightFields;
|
||||
@ -168,6 +170,10 @@ public class NativeSearchQueryBuilder {
|
||||
nativeSearchQuery.setScriptFields(scriptFields);
|
||||
}
|
||||
|
||||
if (!isEmpty(facetRequests)) {
|
||||
nativeSearchQuery.setFacets(facetRequests);
|
||||
}
|
||||
|
||||
if (!isEmpty(aggregationBuilders)) {
|
||||
nativeSearchQuery.setAggregations(aggregationBuilders);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
|
||||
import org.elasticsearch.search.highlight.HighlightBuilder;
|
||||
import org.elasticsearch.search.sort.SortBuilder;
|
||||
import org.springframework.data.elasticsearch.core.facet.FacetRequest;
|
||||
|
||||
/**
|
||||
* NativeSearchQuery
|
||||
@ -37,7 +38,8 @@ public interface SearchQuery extends Query {
|
||||
|
||||
List<SortBuilder> getElasticsearchSorts();
|
||||
|
||||
/*List<FacetRequest> getFacets();*/
|
||||
@Deprecated
|
||||
List<FacetRequest> getFacets();
|
||||
|
||||
List<AbstractAggregationBuilder> getAggregations();
|
||||
|
||||
|
@ -22,6 +22,7 @@ import org.elasticsearch.action.get.MultiGetResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
|
||||
/**
|
||||
* @author Artur Konczak
|
||||
@ -47,7 +48,7 @@ public class CustomResultMapper implements ResultsMapper {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
|
@ -29,13 +29,14 @@ import org.elasticsearch.search.SearchHitField;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.aggregations.Aggregation;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.internal.InternalSearchHitField;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.elasticsearch.core.domain.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.entities.Car;
|
||||
|
||||
/**
|
||||
@ -68,7 +69,7 @@ public class DefaultResultMapperTests {
|
||||
Aggregations aggregations = mock(Aggregations.class);
|
||||
Iterator<Aggregation> iter = Collections.singletonList(aggregationToReturn).iterator();
|
||||
|
||||
when(aggregations.iterator()).thenReturn(iter);
|
||||
when(aggregations.iterator()).thenReturn(iter).thenReturn(iter);
|
||||
when(aggregations.get("engine")).thenReturn(aggregationToReturn);
|
||||
when(response.getAggregations()).thenReturn(aggregations);
|
||||
|
||||
@ -76,6 +77,7 @@ public class DefaultResultMapperTests {
|
||||
AggregatedPage<Car> page = (AggregatedPage<Car>) resultMapper.mapResults(response, Car.class, null);
|
||||
|
||||
//Then
|
||||
page.hasFacets();
|
||||
assertThat(page.hasAggregations(), is(true));
|
||||
assertThat(page.getAggregation("engine").getName(), is("Diesel"));
|
||||
}
|
||||
@ -132,7 +134,7 @@ public class DefaultResultMapperTests {
|
||||
}
|
||||
|
||||
private Aggregation createCarAggregation() {
|
||||
Aggregation aggregation = mock(Aggregation.class);
|
||||
Aggregation aggregation = mock(Terms.class);
|
||||
when(aggregation.getName()).thenReturn("Diesel");
|
||||
return aggregation;
|
||||
}
|
||||
|
@ -41,9 +41,14 @@ import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.elasticsearch.ElasticsearchException;
|
||||
import org.springframework.data.elasticsearch.annotations.Document;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.AggregatedPage;
|
||||
import org.springframework.data.elasticsearch.core.aggregation.impl.AggregatedPageImpl;
|
||||
import org.springframework.data.elasticsearch.core.query.*;
|
||||
import org.springframework.data.elasticsearch.entities.*;
|
||||
import org.springframework.data.util.CloseableIterator;
|
||||
@ -632,12 +637,12 @@ public class ElasticsearchTemplateTests {
|
||||
// when
|
||||
Page<String> page = elasticsearchTemplate.queryForPage(searchQuery, String.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<String> values = new ArrayList<String>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
values.add((String) searchHit.field("message").value());
|
||||
}
|
||||
return new PageImpl<T>((List<T>) values);
|
||||
return new AggregatedPageImpl<T>((List<T>) values);
|
||||
}
|
||||
});
|
||||
// then
|
||||
@ -791,7 +796,7 @@ public class ElasticsearchTemplateTests {
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> result = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
String message = searchHit.getFields().get("message").getValue();
|
||||
@ -802,7 +807,7 @@ public class ElasticsearchTemplateTests {
|
||||
}
|
||||
|
||||
if (result.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) result);
|
||||
return new AggregatedPageImpl<T>((List<T>) result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -843,7 +848,7 @@ public class ElasticsearchTemplateTests {
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 10000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> result = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
String message = searchHit.getFields().get("message").getValue();
|
||||
@ -854,7 +859,7 @@ public class ElasticsearchTemplateTests {
|
||||
}
|
||||
|
||||
if (result.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) result);
|
||||
return new AggregatedPageImpl<T>((List<T>) result);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -892,7 +897,7 @@ public class ElasticsearchTemplateTests {
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> chunk = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
@ -904,7 +909,7 @@ public class ElasticsearchTemplateTests {
|
||||
chunk.add(user);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) chunk);
|
||||
return new AggregatedPageImpl<T>((List<T>) chunk);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -937,7 +942,7 @@ public class ElasticsearchTemplateTests {
|
||||
while (hasRecords) {
|
||||
Page<SampleEntity> page = elasticsearchTemplate.scroll(scrollId, 5000L, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> chunk = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
@ -949,7 +954,7 @@ public class ElasticsearchTemplateTests {
|
||||
chunk.add(user);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) chunk);
|
||||
return new AggregatedPageImpl<T>((List<T>) chunk);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -1243,7 +1248,7 @@ public class ElasticsearchTemplateTests {
|
||||
|
||||
Page<SampleEntity> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> chunk = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
@ -1256,7 +1261,7 @@ public class ElasticsearchTemplateTests {
|
||||
chunk.add(user);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) chunk);
|
||||
return new AggregatedPageImpl<T>((List<T>) chunk);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -1310,7 +1315,7 @@ public class ElasticsearchTemplateTests {
|
||||
// then
|
||||
Page<SampleEntity> page = elasticsearchTemplate.queryForPage(searchQuery, SampleEntity.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<SampleEntity> values = new ArrayList<SampleEntity>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
SampleEntity sampleEntity = new SampleEntity();
|
||||
@ -1318,7 +1323,7 @@ public class ElasticsearchTemplateTests {
|
||||
sampleEntity.setMessage((String) searchHit.getSource().get("message"));
|
||||
values.add(sampleEntity);
|
||||
}
|
||||
return new PageImpl<T>((List<T>) values);
|
||||
return new AggregatedPageImpl<T>((List<T>) values);
|
||||
}
|
||||
});
|
||||
assertThat(page, is(notNullValue()));
|
||||
@ -1480,7 +1485,7 @@ public class ElasticsearchTemplateTests {
|
||||
.withTypes(TYPE_NAME).withQuery(matchAllQuery()).build();
|
||||
Page<Map> sampleEntities = elasticsearchTemplate.queryForPage(searchQuery, Map.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<Map> chunk = new ArrayList<Map>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
if (response.getHits().getHits().length <= 0) {
|
||||
@ -1495,7 +1500,7 @@ public class ElasticsearchTemplateTests {
|
||||
chunk.add(person);
|
||||
}
|
||||
if (chunk.size() > 0) {
|
||||
return new PageImpl<T>((List<T>) chunk);
|
||||
return new AggregatedPageImpl<T>((List<T>) chunk);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -1994,7 +1999,7 @@ public class ElasticsearchTemplateTests {
|
||||
SearchQuery searchQuery = new NativeSearchQueryBuilder().withQuery(matchAllQuery()).withTypes("hetro").withIndices(INDEX_1_NAME, INDEX_2_NAME).build();
|
||||
Page<ResultAggregator> page = elasticsearchTemplate.queryForPage(searchQuery, ResultAggregator.class, new SearchResultMapper() {
|
||||
@Override
|
||||
public <T> Page<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
public <T> AggregatedPage<T> mapResults(SearchResponse response, Class<T> clazz, Pageable pageable) {
|
||||
List<ResultAggregator> values = new ArrayList<ResultAggregator>();
|
||||
for (SearchHit searchHit : response.getHits()) {
|
||||
String id = String.valueOf(searchHit.getSource().get("id"));
|
||||
@ -2002,7 +2007,7 @@ public class ElasticsearchTemplateTests {
|
||||
String lastName = StringUtils.isNotEmpty((String) searchHit.getSource().get("lastName")) ? (String) searchHit.getSource().get("lastName") : "";
|
||||
values.add(new ResultAggregator(id, firstName, lastName));
|
||||
}
|
||||
return new PageImpl<T>((List<T>) values);
|
||||
return new AggregatedPageImpl<T>((List<T>) values);
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user