简体   繁体   English

Elasticsearch NEST API,搜索多个索引

[英]Elasticsearch NEST API, Searching Multiple Indices

If one is seraching several indexes at the same time, is there any way to say that if searching index A, then add this filter and if searching index B then add a different filter.如果同时搜索多个索引,有没有办法说如果搜索索引A,则添加此过滤器,如果搜索索引B,则添加不同的过滤器。

For example:例如:

var filters = new List<Func<QueryContainerDescriptor<PropertySearchResult>, QueryContainer>>();
filters.Add(fq => fq.Term(t => t.Field(f => f.PromoterId).Value(user.Id)));
filters.Add(fq => fq.Term(t => t.Field(f => f.SubscriptionId).Value(subscriptionId)));
string indicies = String.Join(",", Utils.SupportedCountries.Select(c => c.Key.ToLower()).ToArray());
var result = await ElasticSearchConfig.GetClient().DeleteByQueryAsync<PropertySearchResult>(u => u
               .Index(indicies)
               .Query(q => q
               .Bool(bq => bq.Filter(filters))));

at the moment, all indices will be subject to the same filters but I would like to vary the filters based on which index is being searched.目前,所有索引都将使用相同的过滤器,但我想根据正在搜索的索引来改变过滤器。

Add(with &&) a term query to each of your filters向每个过滤器添加(使用 &&)一个术语查询

.Term("_index", A)

Check this link https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html检查此链接https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-index-field.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM