아키텍처를 변경하기 위해 몇 가지 테스트를하고 있습니다. MongoDB를 삭제하고 대신 ElasticSearch를 사용하려고합니다. 그러나 나는이 기술을 정말로 모른다. 드라이버로 NEST를 사용 중이며 mongo에서 사용했던 쿼리를 번역 할 수 없습니다.C# NEST Elastic 검색 쿼리 여러 조건
public async Task<IEnumerable<Keyword>> GetKeywordsAsync(string prefix, int startIndex, int totalItems, int minimumTotalSearch, CancellationToken cancellationToken)
{
return await _mongoReader.GetEntitiesAsync<KeywordEntity, Keyword>(CollectionName,
queryable =>
queryable.Where(entity => entity.KeywordName.StartsWith(prefix) && entity.TotalSearch >= minimumTotalSearch)
.OrderBy(entity => entity.KeywordName)
.Select(_keywordConverter.GetConverter())
.Skip(startIndex)
.Take(totalItems),
cancellationToken).ConfigureAwait(false);
}
public async Task<IEnumerable<TModel>> GetEntitiesAsync<TDocument, TModel>(string collectionName,
Func<IMongoQueryable<TDocument>, IMongoQueryable<TModel>> getQueryable,
CancellationToken cancellationToken)
{
var documents = GetDocuments<TDocument>(collectionName);
var query = getQueryable(documents.AsQueryable());
return await query.ToListAsync(cancellationToken).ConfigureAwait(false);
}
그리고 여기에 내가 ElasticSearch 위해 만든 간단한 발견이다 ...
이public async Task<IEnumerable<TModel>> FindAsync<TModel, TValue>(string index,
Expression<Func<TModel, TValue>> findExpression, TValue value, int limit,
CancellationToken cancellationToken) where TModel : class
{
var searchRequest = new SearchRequest<TModel>(index)
{
Query =
Query<TModel>.Match(
a => a.Field(findExpression).Query(string.Format(CultureInfo.InvariantCulture, "{0}", value))),
Size = limit
};
var resGet = await _elasticClientFactory.Create().SearchAsync<TModel>(searchRequest, cancellationToken).ConfigureAwait(false);
return resGet?.Documents;
}
문제는 내가 탄성 내 쿼리 몽고을 변환 할 수 없습니다입니다
그것은 고통 스럽다했지만 > 솔루션 -
{
"query": {
"bool": {
"must": [
{"range" : { "totalSearch" : { "gte" : minimumTotalSearch }}},
{"prefix": { "keywordName": prefix}}
]
}
},
"from": startIndex,
"size": totalItems
}
: 일부 후 여기에 탄성 쿼리입니다
var result =
ecf.Create()
.Search<KeywordEntity>(
a => a.Query(
z =>
z.Bool(
e =>
e.Must(r => r.Range(t => t.Field(y => y.TotalSearch).GreaterThanOrEquals(minimumTotalSearch)),
t => t.Prefix(y => y.KeywordName, prefix)))).Index("keywords"));
을하지만 이것은 (/ 스킵없이 아주 쉽게되는 소요)이 쿼리를 할 수있는 최선의 방법 인 경우 지금은 자신을 부탁 해요 : 나는 C#에서 쿼리를 할 수있는 방법을 발견 투쟁 코딩. 내가 새로 왔기 때문에 더 최적화 된 쿼리가있을 수 있습니다 ...
쿼리가 수행하려고하는 것을 설명 할 수 있다면 좋을 것입니다. ES 쿼리를 공식화하는 데 도움이됩니다. mongoDb에 익숙하지 않다. – pratikvasa