Curator API returns None

Hi there,

I'm attempting to write a python code that will perform the actions that I'm currently doing in the curator-cli. The goal is to have Lambda that will perform several actions that are related but not restricted to ELK and Curator.

Some actions I was able to perform while others are not clear as to why they aren't working.
For example, snapshots are successful, but any indices actions fails.

Using this code:

client = elasticsearch.Elasticsearch()
ilo = curator.IndexList(client)

This will print all the indices, but if I'll do:

ilo = curator.IndexList(client).filter_by_regex(kind='prefix', value='kubernetes-')

It will fail with:
TypeError: Not an IndexList object. Type: <type 'NoneType'>.

Any idea?

You cannot do it this way. The object has to first be instantiated.

ilo = curator.IndexList(client)
ilo.filter_by_regex(kind='prefix', value='Kubernetes-')
curator.Replicas(ilo, count=2).do_action()

The above should work. 3 steps instead of 2. If it doesn't, then do the same with the Replicas object. Instantiate first, then do_action().

I should probably point out that you got that result because you're assigning the
output of an object method (filter_by_regex) to ilo, rather than making ilo an object by instantiating it on its own. Because of this, you cannot pass ilo to curator.Replicas, because it's not actually an IndexList object.

Thanks, it worked out.

So, if using the filter, how can I retrieve and print the index list that was filtered out?

Once you have an IndexList object, the working list is always stored in the indices instance variable (it's in the documentation, but the methods and variables are, unfortunately, listed alphabetically, so it's down the page pretty far).

ilo = curator.IndexList(client)
print(ilo.indices) # Prints all discovered indices (the current working list)
ilo.filter_by_regex(kind='prefix', value='kubernetes-') 
print(ilo.indices) # Prints the current working list (post-filter)

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.