2

I searched NEST docs but seems to cant find a proper answer for it. My question is how to search multiple indices against some index pattern using NEST? e.g

if I have indices with following names in Elasticsearch DB

media-2017-10, media-2018-03, media-2018-04

For specifying my selected indices, I need to use wild card character * like this:

client.Search<Media>(s => s
   .Index("media-*")
   . query goes here .....

Is it possible in NEST ?

Faisal Mq
  • 5,036
  • 4
  • 35
  • 39

2 Answers2

2

Yes, this works. Try it :)

.Index(...) accepts wildcard indices

Russ Cam
  • 124,184
  • 33
  • 204
  • 266
0

You can also search in multiple indices in that way:

var allIndices = new[] {
        "media-*",
        "docs-*",
        "common-*"           
    };

Nest.Indices allIndices = allIndices;
return _elasticClient
            .SearchAsync<EsBaseModel>(s => s
                .Index( allIndices)
                .Size(_esConfig.MaxCallIDsSize)
                .RequestConfiguration(r => r.RequestTimeout(TimeSpan.FromMinutes(5)))
                .Query(q =>
                    q.Match(m => m.Field("fieldname").Query(condition))                        
                ));

Steps:

Just create an array with string indices. Indices can be explicit or implicit using any pattern supported in Nest client docs.

Notice - neet to put attention to optimize the searching, since it could take a while to search in all the indices that you've provided. (optimize can be achieved by ignoring very old dates, limit the results, etc...)

Ester Kaufman
  • 708
  • 10
  • 20