Fix #6463: Add support for default suggestions for suggestion API (#9090)

This commit is contained in:
Sriharsha Chintalapani 2022-12-02 10:31:37 -08:00 committed by GitHub
parent 0f889e0327
commit 14d82ee7b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 47 additions and 3 deletions

View File

@ -22,7 +22,7 @@ GLOSSARY_TERM_ELASTICSEARCH_INDEX_MAPPING = textwrap.dedent(
"type": "text"
},
"name": {
"type": "text",
"type": "keyword",
"fields": {
"keyword": {
"type": "keyword",

View File

@ -89,6 +89,7 @@ TABLE_ELASTICSEARCH_INDEX_MAPPING = textwrap.dedent(
"properties": {
"name": {
"type": "keyword",
"normalizer": "lowercase_normalizer",
"fields": {
"keyword": {
"type": "keyword",
@ -151,6 +152,7 @@ TABLE_ELASTICSEARCH_INDEX_MAPPING = textwrap.dedent(
},
"name": {
"type": "keyword",
"normalizer": "lowercase_normalizer",
"fields": {
"keyword": {
"type": "keyword",
@ -188,6 +190,7 @@ TABLE_ELASTICSEARCH_INDEX_MAPPING = textwrap.dedent(
},
"name": {
"type": "keyword",
"normalizer": "lowercase_normalizer",
"fields": {
"keyword": {
"type": "keyword",

View File

@ -60,6 +60,7 @@ import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.BucketOrder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder;
@ -353,6 +354,42 @@ public class SearchResource {
return Response.status(OK).entity(suggest.toString()).build();
}
@GET
@Path("/aggregate")
@Operation(
operationId = "getAggregateFields",
summary = "Get Aggregated Fields",
tags = "search",
description = "Get Aggregated Fields from Entities.",
responses = {
@ApiResponse(
responseCode = "200",
description = "Table Aggregate API",
content = @Content(mediaType = "application/json", schema = @Schema(implementation = Suggest.class)))
})
public Response aggregate(
@Context UriInfo uriInfo,
@Context SecurityContext securityContext,
@DefaultValue("table_search_index") @QueryParam("index") String index,
@Parameter(description = "Field in an entity.") @QueryParam("field") String fieldName,
@Parameter(description = "Size field to limit the no.of results returned, defaults to 10")
@DefaultValue("10")
@QueryParam("size")
int size,
@DefaultValue("false") @QueryParam("deleted") String deleted)
throws IOException {
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder
.aggregation(
AggregationBuilders.terms(fieldName).field(fieldName).size(MAX_AGGREGATE_SIZE).order(BucketOrder.key(true)))
.size(0);
searchSourceBuilder.timeout(new TimeValue(30, TimeUnit.SECONDS));
String response =
client.search(new SearchRequest(index).source(searchSourceBuilder), RequestOptions.DEFAULT).toString();
return Response.status(OK).entity(response).build();
}
private SearchSourceBuilder buildAggregateSearchBuilder(String query, int from, int size) {
QueryStringQueryBuilder queryBuilder = QueryBuilders.queryStringQuery(query).lenient(true);
SearchSourceBuilder searchSourceBuilder = searchBuilder(queryBuilder, null, from, size);

View File

@ -33,7 +33,7 @@
"type": "text"
},
"name": {
"type": "text",
"type": "keyword",
"fields": {
"keyword": {
"type": "keyword",

View File

@ -72,6 +72,7 @@
"properties": {
"name": {
"type": "keyword",
"normalizer": "lowercase_normalizer",
"fields": {
"keyword": {
"type": "keyword",
@ -134,6 +135,7 @@
},
"name": {
"type": "keyword",
"normalizer": "lowercase_normalizer",
"fields": {
"keyword": {
"type": "keyword",
@ -171,6 +173,7 @@
},
"name": {
"type": "keyword",
"normalizer": "lowercase_normalizer",
"fields": {
"keyword": {
"type": "keyword",
@ -245,6 +248,7 @@
},
"name": {
"type": "keyword",
"normalizer": "lowercase_normalizer",
"fields": {
"keyword": {
"type": "keyword",

View File

@ -33,7 +33,7 @@
"type": "text"
},
"name": {
"type": "text",
"type": "keyword",
"fields": {
"keyword": {
"type": "keyword",