Elasticsearch search across multiple indexes - ignore non-existent indexes

I have an elastic cluster where my indexes contain the current date - for example:

example-idex-2016-07-26 --> exists example-idex-2016-07-25 --> exists example-idex-2016-07-24 --> doesn't exist (weekend) ... 

Is it possible to query multiple indexes, ignoring those that do not exist. For example, these are WORKS :

 return elastic.search({ index: [ "example-idex-2016-07-26", "example-idex-2016-07-25"], ], ... }); 

While this one returns 404 :

 return elastic.search({ index: [ "example-idex-2016-07-25", "example-idex-2016-07-24"], //this doesn't exist ], ... }); 

I would expect the second example to return documents only from the 25th.

+1
angularjs elasticsearch
source share
1 answer

If you use a wildcard, for example-idex-2016-07-* , you do not need to worry about this, and the ES will determine the corresponding indexes.

If you really want to list indexes, you can specify ignoreUnavailable: true in your search call:

 return elastic.search({ index: [ "example-idex-2016-07-25", "example-idex-2016-07-24"], //this doesn't exist ], ignoreUnavailable: true, ... }); 

Alternatively, you can also use index aliases and request only that alias. When creating a new index, you also add this alias to the index. The good thing about this is that your client code does not need to be changed and will always request only an alias, i.e. Implicitly, all indexes that have this alias.

+3
source share

All Articles