When using High Level Rest Client Java API to produce search query, using AggregationBuilders.topHits("th").sort("_score", SortOrder.DESC) caused query to contain duplicate sort clauses.
This commit is contained in:
parent
eb1639c5fc
commit
3a20ff7e86
|
@ -237,8 +237,9 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHit
|
||||||
}
|
}
|
||||||
if (name.equals(ScoreSortBuilder.NAME)) {
|
if (name.equals(ScoreSortBuilder.NAME)) {
|
||||||
sort(SortBuilders.scoreSort().order(order));
|
sort(SortBuilders.scoreSort().order(order));
|
||||||
|
} else {
|
||||||
|
sort(SortBuilders.fieldSort(name).order(order));
|
||||||
}
|
}
|
||||||
sort(SortBuilders.fieldSort(name).order(order));
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,8 +255,9 @@ public class TopHitsAggregationBuilder extends AbstractAggregationBuilder<TopHit
|
||||||
}
|
}
|
||||||
if (name.equals(ScoreSortBuilder.NAME)) {
|
if (name.equals(ScoreSortBuilder.NAME)) {
|
||||||
sort(SortBuilders.scoreSort());
|
sort(SortBuilders.scoreSort());
|
||||||
|
} else {
|
||||||
|
sort(SortBuilders.fieldSort(name));
|
||||||
}
|
}
|
||||||
sort(SortBuilders.fieldSort(name));
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,6 @@ import org.elasticsearch.search.aggregations.AggregationBuilder;
|
||||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||||
import org.elasticsearch.search.aggregations.AggregatorTestCase;
|
import org.elasticsearch.search.aggregations.AggregatorTestCase;
|
||||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||||
import org.elasticsearch.search.aggregations.metrics.TopHits;
|
|
||||||
import org.elasticsearch.search.aggregations.support.AggregationInspectionHelper;
|
import org.elasticsearch.search.aggregations.support.AggregationInspectionHelper;
|
||||||
import org.elasticsearch.search.sort.SortOrder;
|
import org.elasticsearch.search.sort.SortOrder;
|
||||||
|
|
||||||
|
@ -207,4 +206,10 @@ public class TopHitsAggregatorTests extends AggregatorTestCase {
|
||||||
reader.close();
|
reader.close();
|
||||||
directory.close();
|
directory.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSortByScore() throws Exception {
|
||||||
|
// just check that it does not fail with exceptions
|
||||||
|
testCase(new MatchAllDocsQuery(), topHits("_name").sort("_score", SortOrder.DESC));
|
||||||
|
testCase(new MatchAllDocsQuery(), topHits("_name").sort("_score"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue