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_timeouttimeoutupdate_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_indicesexpand_wildcardshumanignore_unavailablelocal
π« 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_indicesexpand_wildcardsignore_unavailablelocal
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_indicesexpand_wildcardsignore_unavailablemaster_timeouttimeout
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_indicesexpand_wildcardsignore_unavailablemaster_timeouttimeout
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_indicesexpand_wildcardsignore_unavailablemaster_timeouttimeout
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_indicesexpand_wildcardsfielddatafieldsignore_unavailablequeryrecyclerrequest
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_indicesexpand_wildcardsforceignore_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_indicesexpand_wildcardsforceignore_unavailablewait_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_indicesexpand_wildcardsignore_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_indicesexpand_wildcardsflushignore_unavailablemax_num_segmentsonly_expunge_deleteswait_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_indicesexpand_wildcardsflushignore_unavailablemax_num_segmentsonly_expunge_deleteswait_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_indicesexpand_wildcardshumanignore_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_indicesexpand_wildcardsignore_unavailableonly_ancient_segmentswait_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_indicesexpand_wildcardsignore_unavailablemaster_timeouttimeoutupdate_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_indicesexpand_wildcardsignore_unavailablelocal
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_indicesexpand_wildcardsignore_unavailableinclude_defaultslocal
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_indicesexpand_wildcardsignore_unavailablelocal
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_timeouttimeout
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:
localtimeout
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_timeouttimeout
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_indicesexpand_wildcardsignore_unavailablelocal
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_indicesexpand_wildcardsignore_unavailablelocal
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_timeouttimeout
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_indicesexpand_wildcardsflat_settingsignore_unavailablemaster_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_indicesexpand_wildcardsflat_settingshumanignore_unavailablelocal
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:
createflat_settingsmaster_timeoutop_typeordertimeoutversionversion_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_settingslocalmaster_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:
localmaster_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_timeouttimeoutversionversion_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_indicesexpand_wildcardsignore_unavailablemaster_timeoutrequest_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_indicesexpand_wildcardsignore_unavailablelocal
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: bothindexandnameare 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_fieldsfielddata_fieldsfieldsgroupshumanleveltypes
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_onlydetailedhuman
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_indicesexpand_wildcardshumanignore_unavailableverbose
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_indicesexpand_wildcardshumanignore_unavailablestatus
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:
analyzerattributeschar_filterexplainfieldfilterformatprefer_localtexttokenizer
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_indicesanalyze_wildcardanalyzerdefault_operatordfexplainexpand_wildcardsignore_unavailablelenientlowercase_expanded_termsqrewrite
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>
π COPYRIGHT AND LICENSE π
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 πβ¨
π¦ where this page comes from
- debian bookworm: libsearch-elasticsearch-client-2-0-perl 6.81-1 Β· Apache-2.0
- debian trixie: libsearch-elasticsearch-client-2-0-perl 6.81-1 Β· Apache-2.0
- ubuntu jammy: libsearch-elasticsearch-client-2-0-perl 6.81-1 Β· Apache-2.0
- ubuntu noble: libsearch-elasticsearch-client-2-0-perl 6.81-1 Β· Apache-2.0
- ubuntu resolute: libsearch-elasticsearch-client-2-0-perl 6.81-1 Β· Apache-2.0
- ubuntu stonking: libsearch-elasticsearch-client-2-0-perl 6.81-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms