我是ElasticSearch的新手,我使用NEST來運行我的查詢。我需要能夠將X數量的過濾條件添加到我的查詢中。C#巢 - ElasticSearch
現在我的查詢看起來是這樣的:
var page = new Page
{
Id = 1,
Name = "JR-11 Hyper black"
};
var tags = new Dictionary<string, string[]>
{
{ "Size", new[] { "16", "17", "18" }},
{ "Color", new[] { "Bronze", "Hyper Black", "Flat Black" }}
};
page.Tags = tags;
ElasticClient.Index(page, idx => idx.Index("pages"));
var result = ElasticClient.Search<Page>(
body => body.Query(query => query.ConstantScore(
csq => csq.Filter(filter => filter.Term("tags.Size", "17"))))
.Take(1000));
var pages = result.Documents.ToList();
我的問題是與csq.Filter(filer => filter.Term("tags.Storlek")
我需要能夠增加這種過濾器的動態量。在我使用的2.3版本的文檔中找不到任何東西。
謝謝!但是,filterTerms應包含哪些內容?而不應該combinedFilters在一些什麼連接?而不是在foor-loop中重寫? –
那麼'filterTerm'當然是由你定義的。你需要一個動態的過濾器,所以這就是你定義它們的地方。 'combinedFilters'被覆蓋,是的,但是包含已經定義的過濾器的對象以及新添加的過濾器。通常實現實際上返回相同的對象。有關流暢接口的更多信息,請參閱https://en.wikipedia.org/wiki/Fluent_interface。 –