Search...Indices(3pm)

πŸ’– NAME πŸ’–

Search::Elasticsearch::Client::2_0::Direct::Indices β€” a whole entire client for running index-level requests, bestie. (You're reading Search...Indices(3pm), the User Contributed Perl Documentation version, and jsyk this is part 1 of 3 so don't you dare leave yet. ✨)


πŸŽ€ VERSION πŸŽ€

version 6.81


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so this module is the plug for making index-level requests. We're talking: creating and deleting indices, managing type mappings, index settings, warmers, index templates and aliases. All of it. She does it all. πŸ‘‘

And for the record, she does Search::Elasticsearch::Role::Client::Direct. Periodt.


πŸ‘‘ INDEX METHODS πŸ‘‘

✨ create() ✨

$result = $e->indices->create(
    index => 'my_index'             # required

    body  => {                      # optional
        index settings
        mappings
        warmers
    }
);

The create() method makes you a brand new index. And here's the cute part β€” you can optionally pile on index settings, type mappings and index warmers at the same exact time. Two birds, one slay. πŸ•ŠοΈ

Query string parameters:

  • master_timeout
  • timeout
  • update_all_types

Peep the create index docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html for more info.


🌸 get() 🌸

$response = $e->indices->get(
    index   => 'index'   | \@indices    # optional
    feature => 'feature' | \@features   # optional
);

Returns the aliases, settings, mappings, and warmers for whatever indices you point at. The feature parameter can be set to none, or one or more of these little guys: _settings, _mappings, _warmers and _aliases.

Peep the get index docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-index.html.

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • human
  • ignore_unavailable
  • local

πŸ’« exists() πŸ’«

$bool = $e->indices->exists(
    index => 'index' | \@indices    # required
);

The exists() method hands you back 1 or the empty string, telling you whether that index (or those indices) exist. Yes/no energy. Simple. Iconic. πŸ’…

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • local

Peep the index exists docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-indices-exists.html for more info.


πŸ—‘οΈ delete() πŸ—‘οΈ

$response = $e->indices->delete(
    index => 'index' | \@indices    # required
);

The delete() method deletes the specified indices. Gone. Gone gone. Not me being emotional about it. 😭

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • master_timeout
  • timeout

Peep the delete index docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html for more info.


πŸšͺ close() πŸšͺ

$response = $e->indices->close(
    index => 'index' | \@indices    # required
);

The close() method closes the specified indices β€” it chills out their resource usage while keeping them reopenable later. It's giving "napping, not ghosting". 😴

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • master_timeout
  • timeout

Peep the close index docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html for more info.


πŸ”“ open() πŸ”“

$response = $e->indices->open(
    index => 'index' | \@indices    # required
);

The open() method opens closed indices. She's back. She's refreshed. Main character re-entrance. ✨

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • master_timeout
  • timeout

Peep the open index docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html for more info.


🧹 clear_cache() 🧹

$response = $e->indices->clear_cache(
    index => 'index' | \@indices        # optional
);

The clear_cache() method is used to clear the in-memory filter, fielddata, or id cache for the specified indices. Spring cleaning but make it distributed. 🌷

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • fielddata
  • fields
  • ignore_unavailable
  • query
  • recycler
  • request

Peep the clear_cache docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-clearcache.html for more info.


πŸ”„ refresh() πŸ”„

$response = $e->indices->refresh(
    index => 'index' | \@indices    # optional
);

The refresh() method refreshes the specified indices (or all indices if you don't specify), which lets recent changes become visible to search. And ngl, this process normally happens automatically once every second by default β€” so she's out here doing it for you anyway. πŸ™ˆ

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • force
  • ignore_unavailable

Peep the refresh index docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-refresh.html for more info.


πŸ’Ύ flush() πŸ’Ύ

$response = $e->indices->flush(
    index => 'index' | \@indices    # optional
);

The flush() method makes the specified indices (or all indices) get written to disk with an fsync, and it clears out the transaction log. And yes, this process normally happens automatically too. She's just being extra for you. 🫢

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • force
  • ignore_unavailable
  • wait_if_ongoing

Peep the flush index docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-flush.html for more info.


πŸͺ„ flush_synced() πŸͺ„

$respnse = $e->indices->flush_synced(
    index => 'index' | \@indices    # optional
);

The flush_synced() method does a synchronised flush() on the primaries and replicas of all the specified indices. In other words β€” after flushing it tries to write a sync_id on the primaries and replicas to mark them as containing the same documents. During recovery, if a replica has the same sync_id as the primary, then it doesn't need to check whether the segment files on primary and replica are the same, and it can move on directly to just replaying the translog. This can greatly speed up recovery. Speeeedy. 🏎️✨

Synced flushes happens automatically in the background on indices that have not received any writes for a while, but the flush_synced() method can be used to trigger this process manually, eg before shutting down. Any new commits immediately break the sync. (Yes, immediately. She is fragile like that. πŸ’”)

Peep the flush synced docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-synced-flush.html for more info.

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable

πŸ‹οΈ forcemerge() πŸ‹οΈ

$response = $e->indices->forcemerge(
    index => 'index' | \@indices    # optional
);

The forcemerge() method rewrites all the data in an index into at most max_num_segments.

⚠️ Bestie. Listen. This is a very heavy operation and should only be run with care, and only on indices that are no longer being updated. Do not just casually hit this on a live index, I am begging. 😭

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • flush
  • ignore_unavailable
  • max_num_segments
  • only_expunge_deletes
  • wait_for_merge

Peep the forcemerge docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-forcemerge.html for more info.


⚠️ optimize() ⚠️

The optimize() method is deprecated in 2.x and will be replaced by forcemerge();

$response = $e->indices->optimize(
    index => 'index' | \@indices    # optional
);

The optimize() method rewrites all the data in an index into at most max_num_segments.

🚨 Same warning as above, and louder: this is a very heavy operation and should only be run with care, and only on indices that are no longer being updated. She's also deprecated, so... it's giving legacy. πŸ’€

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • flush
  • ignore_unavailable
  • max_num_segments
  • only_expunge_deletes
  • wait_for_merge

Peep the optimize index docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-optimize.html for more info.


πŸ” get_upgrade() πŸ”

$response = $e->indices->get_upgrade(
    index => 'index' | \@indices    # optional
);

The get_upgrade() method returns info about which indices need to be upgraded β€” and you can actually do that upgrade with the upgrade() method. Teamwork! 🀝

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • human
  • ignore_unavailable

Peep the upgrade docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-upgrade.html for more info.


⬆️ upgrade() ⬆️

$response = $e->indices->upgrade(
    index => 'index' | \@indices    # optional
);

The upgrade() method upgrades all segments in the specified indices to the latest format. Glow-up, but for segments. πŸ’…

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • only_ancient_segments
  • wait_for_completion

Peep the upgrade docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-upgrade.html for more info.


✨ and that's part 1, bestie β€” parts 2 and 3 are right behind me, don't go anywhere πŸ’–

✨ MAPPING METHODS ✨


put_mapping()

$response = $e->indices->put_mapping(
    index => 'index' | \@indices    # optional,
    type  => 'type',                # required

    body  => { mapping }            # required
)

ok so put_mapping()</p> is the one that creates or updates a type mapping on an index that already exists, bestie. And listen β€” mapping updates can add new fields, but they cannot overwrite or change fields that are already there. That's the vibe, that's the rule πŸ’…

For instance:

$response = $e->indices->put_mapping(
    index   => 'users',
    type    => 'user',
    body    => {
        user => {
            properties => {
                name => { type => 'string'  },
                age  => { type => 'integer' }
            }
        }
    }
);

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • master_timeout
  • timeout
  • update_all_types

See the put_mapping docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html for more info 🫢


get_mapping()

$result = $e->indices->get_mapping(
    index => 'index' | \@indices    # optional,
    type  => 'type'  | \@types      # optional
);

The get_mapping() method hands you back the type definitions for one, more, or literally all types in one, more, or all indices. So many options, so little time ✨

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • local

See the get_mapping docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html for more info πŸ¦‹


get_field_mapping()

$result = $e->indices->get_field_mapping(
    index => 'index'  | \@indices    # optional,
    type  => 'type'   | \@types      # optional,
    fields => 'field' | \@fields     # required

    include_defaults => 0 | 1
);

The get_field_mapping() method returns the field definitions for one, more, or all fields across one, more, or all types and indices. It's giving field-definition delivery service, no cap πŸ’…

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • include_defaults
  • local

See the get_mapping docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-field-mapping.html for more info 🌸


exists_type()

$bool = $e->indices->exists_type(
    index => 'index' | \@indices    # required,
    type  => 'type'  | \@types      # required
);

The exists_type() method checks if all the types you named actually exist in all the indices you named. Returns 1 or the empty string. Simple. Iconic. ✨

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • local

See the exists_type docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-types-exists.html for more info πŸ’–


πŸŽ€ ALIAS METHODS πŸŽ€


update_aliases()

$response = $e->indices->update_aliases(
    body => { actions }             # required
);

The update_aliases() method changes multiple index aliases atomically β€” as in adding or removing them all at once, no half-measures. For instance:

$response = $e->indices->update_aliases(
    body => {
        actions => [
            { add    => { alias => 'current', index => 'logs_2013_09' }},
            { remove => { alias => 'current', index => 'logs_2013_08' }}
        ]
    }
);

Query string parameters:

  • master_timeout
  • timeout

See the update_aliases docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html for more info 🫢


get_aliases()

$result = $e->indices->get_aliases(
    index   => 'index' | \@indices,     # optional
    alias   => 'alias' | \@aliases      # optional
);

The get_aliases() method returns a list of aliases per index for all the specified indices. It's the alias gossip column of your cluster fr πŸ’…

Query string parameters:

  • local
  • timeout

See the get_aliases docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html for more info 🌈


put_alias()

$response = $e->indices->put_alias(
    index => 'index' | \@indices,       # required
    name  => 'alias',                   # required

    body  => { alias defn }             # optional
);

The put_alias() method creates an index alias. For instance:

$response = $e->indices->put_alias(
    index => 'my_index',
    name  => 'twitter',
    body => {
        filter => { term => { user_id => 'twitter' }}
    }
);

Query string parameters:

  • master_timeout
  • timeout

See the put_alias docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html for more info ✨


get_alias()

$result = $e->indices->get_alias(
    index   => 'index' | \@indices,     # optional
    name    => 'alias' | \@aliases      # optional
);

The get_alias() method returns the alias definitions for the aliases you asked about, in the indices you asked about. Very demure, very specific πŸŽ€

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • local

See the get_alias docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html for more info πŸ¦‹


exists_alias()

$bool = $e->indices->exists_alias(
    index   => 'index' | \@indices,     # optional
    name    => 'alias' | \@aliases      # optional
);

The exists_alias() method returns 1 or the empty string depending on whether the specified aliases exist in the specified indices. Yes/no, bestie. Binary. Iconic πŸ’…

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • local

See the exists_alias docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html for more info 🌸


delete_alias()

$response = $e->indices->delete_alias(
    index   => 'index' | \@indices        # required,
    name    => 'alias' | \@aliases        # required
);

The delete_alias() method deletes one or more aliases from one or more indices. Goodbye, alias. Gone. Not coming back πŸ”₯

Query string parameters:

  • master_timeout
  • timeout

See the delete_alias docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html for more info πŸ’–


🌟 SETTINGS METHODS 🌟


put_settings()

$response = $e->indices->put_settings(
    index   => 'index' | \@indices      # optional

    body    => { settings }
);

The put_settings() method sets the index settings for the specified indices β€” or, if you don't pass index, for all of them. For instance:

$response = $e->indices->put_settings(
    body => {
        "index.refresh_interval" => -1
    }
);

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • flat_settings
  • ignore_unavailable
  • master_timeout

See the put_settings docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-update-settings.html for more info 🫢


get_settings()

$result = $e->indices->get_settings(
    index   => 'index' | \@indices      # optional
    name    => 'name'  | \@names        # optional
);

The get_settings() method retrieves the index settings for the specified indices, or all indices. The settings, served fresh πŸ“

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • flat_settings
  • human
  • ignore_unavailable
  • local

See the get_settings docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-settings.html for more info ✨


🌈 TEMPLATE METHODS 🌈


put_template()

$response = $e->indices->put_template(
    name => 'template'                  # required
    body => { template defn }           # required
);

The put_template() method is used to create or update index templates. New template, who dis πŸ’…

Query string parameters:

  • create
  • flat_settings
  • master_timeout
  • op_type
  • order
  • timeout
  • version
  • version_type

See the put_template docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html for more info πŸ¦‹


get_template()

$result = $e->indices->get_template(
    name  => 'template' | \@templates # optional
);

The get_template() method is used to retrieve a named template. Name it, get it πŸŽ€

Query string parameters:

  • flat_settings
  • local
  • master_timeout

See the get_template docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html for more info 🌸


exists_template()

$result = $e->indices->exists_template(
    name  => 'template'                 # required
);

The exists_template() method is used to check whether the named template exists. Do you exist? Vibes only ✨

Query string parameters:

  • local
  • master_timeout

See the get_template docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html for more info πŸ’–


delete_template()

$response = $e->indices->delete_template(
    name  => 'template'                 # required
);

The delete_template() method is used to delete a named template. Template? Never heard of her πŸ”₯

Query string parameters:

  • master_timeout
  • timeout
  • version
  • version_type

See the delete_template docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html for more info 🌈

πŸ”₯ WARMER METHODS πŸ”₯

put_warmer()

$response = $e->indices->put_warmer(
    index   => 'index' | \@indices,     # optional
    type    => 'type'  | \@types,       # optional
    name    => 'warmer',                # required

    body    => { warmer defn }          # required
);

okay so put_warmer() is the one that makes or updates named warmers β€” and warmers are literally the pre-game ritual for your segments, they get new segments all cozy and warmed up before any actual user search touches them. main character preparation energy fr. like:

$response = $e->indices->put_warmer(
    index   => 'my_index',
    name    => 'date_field_warmer',
    body    => {
        sort => 'date'
    }
);

Query string parameters, bestie:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • master_timeout
  • request_cache

See the put_warmer docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html for more info πŸ’…


get_warmer()

$response = $e->indices->get_warmer(
    index   => 'index'  | \@indices,    # optional
    type    => 'type'   | \@types,      # optional
    name    => 'warmer' | \@warmers,    # optional
);

The get_warmer() method pulls warmers by name. that's it, that's the vibe πŸ¦‹

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • ignore_unavailable
  • local

See the get_warmer docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html for more 🫢


delete_warmer()

$response = $e->indices->get_warmer(
    index   => 'index'  | \@indices,    # required
    name    => 'warmer' | \@warmers,    # required
);

The delete_warmer() method deletes warmers by name. gone, deleted, no more, periodt. πŸ—‘οΈ

heads up: both index and name are required here β€” not optional, don't come for me.

Query string parameters:

  • master_timeout

See the delete_warmer docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-warmers.html for more ✨


πŸ“Š STATS METHODS πŸ“Š

stats()

$result = $e->indices->stats(
    index   => 'index'  | \@indices      # optional
    metric  => 'metric' | \@metrics      # optional
);

The stats() method serves up statistical information about one, more, or literally all the indices. by default it gives you every metric, but you can gatekeep by specifying the metric. it's giving numbers, it's giving data, it's giving lowkey nosy but in a helpful way πŸ’–

Allowed metrics are:

"_all",
"completion"
"docs",
"fielddata",
"filter_cache",
"flush",
"get",
"id_cache",
"indexing",
"merge",
"percolate",
"query_cache",
"refresh",
"request_cache",
"search",
"segments",
"store",
"warmer"

Query string parameters:

  • completion_fields
  • fielddata_fields
  • fields
  • groups
  • human
  • level
  • types

See the stats docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-stats.html for more 🌸


recovery()

$result = $e->indices->recovery(
    index   => 'index' | \@indices      # optional
);

Gives you the tea on on-going shard recoveries. healing era fr 🧚

Query string parameters:

  • active_only
  • detailed
  • human

See the recovery docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-recovery.html for more ⭐


segments()

$result = $e->indices->segments(
    index   => 'index' | \@indices      # optional
);

The segments() method returns info about the segments an index contains. very inside-baseball, very iykyk πŸ‘‘

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • human
  • ignore_unavailable
  • verbose

See the segments docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-segments.html for more πŸ’œ


shard_stores()

$result = $e->indices->shard_stores(
    index   => 'index' | \@indices      # optional
);

The shard_stores() method is how you find out which nodes contain copies of which shards, and whether those shards are allocated or not. like a little shard census πŸ•΅οΈβ€β™€οΈ

Query string parameters:

  • allow_no_indices
  • expand_wildcards
  • human
  • ignore_unavailable
  • status

See the shard_stores docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-shards-stores.html for more πŸŽ€


πŸ” QUERY AND ANALYSIS METHODS πŸ”

analyze()

$result = $e->indices->analyze(
    index   => 'index'                  # optional,
    body    => 'text to analyze'
);

The analyze() method runs the text in the body through whatever analyzer, tokenizer, or token filter you point at β€” and those can be global, or tied to a specific index or field β€” then hands you back the tokens. literally the bestie move for debugging analyzer configs. chef's kiss, ate, no crumbs πŸ”₯

Query string parameters:

  • analyzer
  • attributes
  • char_filter
  • explain
  • field
  • filter
  • format
  • prefer_local
  • text
  • tokenizer

See the analyze docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-analyze.html for more 🌈


validate_query()

$result = $e->indices->validate_query(
    index   => 'index' | \@indices,     # optional
    type    => 'type'  | \@types,       # optional

    body    => { query }
);

The validate_query() method takes a query in the body and checks if it's valid or not. it hits different when explain is set to true, because then it also includes an execution plan in the output. receipts included, periodt πŸ’…

Query string parameters:

  • allow_no_indices
  • analyze_wildcard
  • analyzer
  • default_operator
  • df
  • explain
  • expand_wildcards
  • ignore_unavailable
  • lenient
  • lowercase_expanded_terms
  • q
  • rewrite

See the validate_query docs at http://www.elastic.co/guide/en/elasticsearch/reference/current/indices-validate.html for more πŸ¦‹


πŸ‘‘ AUTHOR πŸ‘‘

Enrico Zimuel <enrico.zimuel@elastic.co>


This software is Copyright (c) 2020 by Elasticsearch BV.

This is free software, licensed under:

The Apache License, Version 2.0, January 2004

and that's a wrap on this whole page bestie 🫢 brought to you by perl v5.32.0, dated 2020-11-25, filed under Search...Indices(3pm). go warm some segments, validate some queries, and slay πŸ’–βœ¨