Skip to content

Commit

Permalink
skip sort in ES query if object empty
Browse files Browse the repository at this point in the history
  • Loading branch information
Junjiequan authored and bpedersen2 committed Jan 19, 2024
1 parent fd8b64e commit a80133b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/elastic-search/elastic-search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ export class ElasticSearchService implements OnModuleInit {
const defaultMinScore = searchParam.text ? 1 : 0;

try {
const isSortEmpty = !sort || JSON.stringify(sort) === "{}";
const searchQuery = this.searchService.buildSearchQuery(searchParam);

const searchOptions = {
track_scores: true,
sort: [{ _score: { order: "desc" } }],
Expand All @@ -279,7 +279,7 @@ export class ElasticSearchService implements OnModuleInit {
_source: [""],
} as SearchRequest;

if (sort) {
if (!isSortEmpty) {
const sortField = Object.keys(sort)[0];
const sortDirection = Object.values(sort)[0];

Expand Down

0 comments on commit a80133b

Please sign in to comment.