ElasticSearch查询多个索引C#

时间:2018-04-06 19:20:17

标签: elasticsearch

是否可以在一个.Search查询中查询多个索引? 我在C#中的例子:

        ConnectionSettings connectionSettings = new ConnectionSettings(new Uri("http://localhost:9200/")); //local PC             
        ElasticClient elasticClient = new ElasticClient(connectionSettings);

        string index1 = "local-neal-test-other1-2018.04.06";
        string index2 = "local-neal-test-other2-2018.04.06";

        //Search query to retrieve info 
        var response = elasticClient.Search<Document2>(s => s
            .Index(index1)
            .Query (q=>q.
                   MatchAll()
                   )
            .Sort(ss => ss 
                 .Descending(p => p.CreatedDate))
             );

示例,我可以将index1和index2放在上面吗?

1 个答案:

答案 0 :(得分:1)

您可以明确告诉ELK使用多个索引:

elasticClient.Search<Document2>(s=>s
    .Index(new [] {"Index_A", "Index_B"})
    ...
)
相关问题