Я создал поисковый дескриптор, чтобы можно было отфильтровать некоторые данные изasticsearch. Похоже, что все мои тесты, выполняющие функции фильтров, проходят, но они не проходят полнотекстовый поиск.
У меня естьперепробовал все варианты, и я растерялся относительно того, почему это происходит.
poco:
[ElasticsearchType(Name = "restaurant")]
public class RestaurantSearchItem
{
public const string IndexName = "restaurants";
[Keyword]
public string Id { get; set; }
[Text]
public string Name { get; set; }
public decimal Rating { get; set; }
public int ReviewCount { get; set; }
public string UrlName { get; set; }
[Keyword]
public string CountryCode { get; set; }
[GeoPoint]
public Geolocation Location { get; set; }
[Keyword]
public string[] CuisineIds { get; set; }
[Keyword]
public string[] StyleIds { get; set; }
public Image[] Images { get; set; }
}
отображение:
await _elasticClient.CreateIndexAsync(
RestaurantSearchItem.IndexName,
i => i.Mappings(ms => ms.Map<RestaurantSearchItem>(m => m.AutoMap())), cancellation);
дескриптор:
var filters = new List<Func<QueryContainerDescriptor<RestaurantSearchItem>, QueryContainer>>();
if (request.Query.CuisineIds?.Any() == true)
{
filters.Add(fq => fq.Terms(t => t.Field(f => f.CuisineIds).Terms(request.Query.CuisineIds)));
}
if (request.Query.StyleIds?.Any() == true)
{
filters.Add(fq => fq.Terms(t => t.Field(f => f.StyleIds).Terms(request.Query.StyleIds)));
}
return descriptor => descriptor
.Query(q => q
.Bool(b => b
.Must(m => m
.MultiMatch(mp => mp
.Query(request.Query.FreeText)
.Fields(f => f
.Fields(r => r.Name))))
.Filter(f => f
.Bool(b1 => b1
.Must(filters)))))
.Sort(o => o.Ascending(r => r.Id))
.From(request.Offset)
.Size(request.PageSize);
}