Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release/1.8.3] Fix Elasticsearch Query API #16426

Merged
merged 1 commit into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ private static Dictionary<string, object> CreateElasticDocument(DocumentIndex do

public string GetFullIndexName(string indexName)
{
ArgumentException.ThrowIfNullOrEmpty(indexName, nameof(indexName));
ArgumentException.ThrowIfNullOrEmpty(indexName);

return GetIndexPrefix() + _separator + indexName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,30 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Nest;
using OrchardCore.Environment.Shell;

namespace OrchardCore.Search.Elasticsearch.Core.Services
{
public class ElasticQueryService : IElasticQueryService
{
private readonly string _indexPrefix;
private readonly IElasticClient _elasticClient;
private readonly ElasticIndexManager _elasticIndexManager;
private readonly ILogger _logger;

public ElasticQueryService(
IElasticClient elasticClient,
ShellSettings shellSettings,
ElasticIndexManager elasticIndexManager,
ILogger<ElasticQueryService> logger
)
{
_indexPrefix = shellSettings.Name.ToLowerInvariant() + "_";
_elasticClient = elasticClient;
_elasticIndexManager = elasticIndexManager;
_logger = logger;
}

public async Task<ElasticTopDocs> SearchAsync(string indexName, string query)
{
ArgumentException.ThrowIfNullOrEmpty(indexName);

var elasticTopDocs = new ElasticTopDocs();

if (_elasticClient == null)
Expand All @@ -40,7 +41,7 @@ public async Task<ElasticTopDocs> SearchAsync(string indexName, string query)
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(query));
var deserializedSearchRequest = _elasticClient.RequestResponseSerializer.Deserialize<SearchRequest>(stream);

var searchRequest = new SearchRequest(_indexPrefix + indexName)
var searchRequest = new SearchRequest(_elasticIndexManager.GetFullIndexName(indexName))
{
Query = deserializedSearchRequest.Query,
From = deserializedSearchRequest.From,
Expand Down