您可以明确地告诉NEST使用多个索引:
client.Search<MyObject>(s=>s .Indices(new [] {"Index_A", "Index_B"}) ...)如果要搜索所有索引
client.Search<MyObject>(s=>s .AllIndices() ...)
或者,如果您要搜索一个索引(不是默认索引)
client.Search<MyObject>(s=>s. .Index("Index_A") ...)请记住,从elasticsearch 19.8开始,您还可以在索引名称上指定通配符
client.Search<MyObject>(s=>s .Index("Index_*") ...)至于你的indexs_query
client.Search<MyObject>(s=>s .AllIndices() .Query(q=>q .Indices(i=>i .Indices(new [] { "INDEX_A", "INDEX_B"}) .Query(iq=>iq.Term("FIELD","VALUE")) .NoMatchQuery(iq=>iq.Term("FIELD", "VALUE")) ) ));更新
这些测试展示了如何使C#的协方差为您工作:
https://github.com/Mpdreamz/NEST/blob/master/src/Nest.Tests.Integration/Search/SubClassSupport/SubClassSupportTests.cs
在您的情况下,如果所有类型都不是共享库的子类,您仍然可以使用“对象”
即:
.Search<object>(s=>s .Types(typeof(Product),typeof(Category),typeof(Manufacturer)) .Query(...) );
这将搜索
/yourdefaultindex/products,categories,manufacturers/_search并设置一个默认值
ConcreteTypeSelector,该默认值可以理解每个返回文档的类型。
使用,
ConcreteTypeSelector(Func<dynamic, Hit<dynamic>,Type>)您可以基于一些json值(动态)或匹配的元数据手动返回类型。



