File: examples.rst

package info (click to toggle)
elasticsearch-curator 8.0.21-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,716 kB
  • sloc: python: 17,838; makefile: 159; sh: 156
file content (94 lines) | stat: -rw-r--r-- 2,465 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
.. _examples:

Examples
========

Each of these examples presupposes that the requisite modules have been imported
and an instance of the Elasticsearch client object has been created:

.. code-block:: python

       import elasticsearch
       import curator

       client = elasticsearch.Elasticsearch()

Filter indices by prefix
++++++++++++++++++++++++

.. code-block:: python

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

The contents of ``ilo.indices`` will be only indices prefixed by ``logstash-``.

Filter indices by suffix
++++++++++++++++++++++++

.. code-block:: python

    ilo = curator.IndexList(client)
    ilo.filter_by_regex(kind='suffix', value='-prod')

The contents of ``ilo.indices`` will be only indices suffixed by ``-prod``.

Filter indices by age (name)
++++++++++++++++++++++++++++

This example will match indices with the following criteria:

* Have a date string of ``%Y.%m.%d``
* Use ``days`` as the unit of time measurement
* Filter indices ``older`` than 5 ``days``

.. code-block:: python

    ilo = curator.IndexList(client)
    ilo.filter_by_age(
        source='name', direction='older', timestring='%Y.%m.%d', unit='days', unit_count=5
    )

The contents of ``ilo.indices`` would then only be indices matching these
criteria.


Filter indices by age (creation_date)
+++++++++++++++++++++++++++++++++++++

This example will match indices with the following criteria:

* Use ``months`` as the unit of time measurement
* Filter indices where the index creation date is ``older`` than 2 ``months`` from
  this moment.

.. code-block:: python

    ilo = curator.IndexList(client)
    ilo.filter_by_age(
        source='creation_date', direction='older', unit='months', unit_count=2
    )

The contents of ``ilo.indices`` would then only be indices matching these
criteria.

Filter indices by age (field_stats)
+++++++++++++++++++++++++++++++++++

This example will match indices with the following criteria:

* Use ``days`` as the unit of time measurement
* Filter indices where the ``timestamp`` field's ``min_value`` is a date ``older``
  than 3 ``weeks`` from this moment.


.. code-block:: python

    ilo = curator.IndexList(client)
    ilo.filter_by_age(
        source='field_stats', direction='older', unit='weeks', unit_count=3,
        field='timestamp', stats_result='min_value'
    )

The contents of ``ilo.indices`` would then only be indices matching these
criteria.