Skip to content

Commit 9cda977

Browse files
committed
refactor: Change Elasticsearch query parameters from string concatenation to JSON formatting
1 parent 27a7ed7 commit 9cda977

File tree

1 file changed

+7
-2
lines changed
  • internal/application/repository/retriever/elasticsearch/v7

1 file changed

+7
-2
lines changed

internal/application/repository/retriever/elasticsearch/v7/repository.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,16 @@ func (e *elasticsearchRepository) buildKeywordSearchQuery(ctx context.Context,
520520
params typesLocal.RetrieveParams,
521521
) (string, error) {
522522
log := logger.GetLogger(ctx)
523+
content, err := json.Marshal(params.Query)
524+
if err != nil {
525+
log.Errorf("[ElasticsearchV7] Failed to marshal query: %v", err)
526+
return "", err
527+
}
523528

524529
filter := e.getBaseConds(params)
525530
query := fmt.Sprintf(
526-
`{"query": {"bool": {"must": [{"match": {"content": "%s"}}], "filter": [%s]}}}`,
527-
params.Query, filter,
531+
`{"query": {"bool": {"must": [{"match": {"content": %s}}], "filter": [%s]}}}`,
532+
string(content), filter,
528533
)
529534

530535
log.Debugf("[ElasticsearchV7] Executing keyword search with query: %s", query)

0 commit comments

Comments
 (0)