Search...Direct(3pm)
yo bestie!! welcome to the User Contributed Perl Documentation for Search::Elasticsearch::Client::7_0::Direct(3pm). This is part 1, so buckle up. π
β¨ NAME β¨
Search::Elasticsearch::Client::7_0::Direct β thin client with full support for Elasticsearch 7.x APIs. No cap, it's giving "native REST API but make it Perl". π
πΈ VERSION πΈ
version 7.715 π
π¦ SYNOPSIS π¦
Okay so first, create a client:
use Search::Elasticsearch;
my $e = Search::Elasticsearch->new(
client => '7_0::Direct'
);
Then index a doc:
$e->index(
index => 'my_index',
type => 'blog_post',
id => 123,
body => {
title => "Elasticsearch clients",
content => "Interesting content...",
date => "2013-09-23"
}
);
Get a doc:
$e->get(
index => 'my_index',
type => 'my_type',
id => 123
);
Search for docs:
$results = $e->search(
index => 'my_index',
body => {
query => {
match => {
title => "elasticsearch"
}
}
}
);
Index-level requests:
$e->indices->create( index => 'my_index' );
$e->indices->delete( index => 'my_index' )
Ingest pipeline requests:
$e->ingest->get_pipeline( id => 'apache-logs' );
Cluster-level requests:
$health = $e->cluster->health;
Node-level requests:
$info = $e->nodes->info;
$stats = $e->nodes->stats;
Snapshot and restore:
$e->snapshot->create_repository(
repository => 'my_backups',
type => 'fs',
settings => {
location => '/mnt/backups'
}
);
$e->snapshot->create(
repository => 'my_backups',
snapshot => 'backup_2014'
);
Task management:
$e->tasks->list;
cat debugging:
say $e->cat->allocation;
say $e->cat->health;
Cross-cluster replication requests:
say $e->ccr->follow;
Index lifecycle management requests:
say $e->ilm->put_lifecycle;
π DESCRIPTION π
The Search::Elasticsearch::Client::7_0::Direct class provides the Elasticsearch 7.x compatible client returned by:
$e = Search::Elasticsearch->new(
client => "7_0::Direct" # default
);
It is intended to be as close as possible to the native REST API that Elasticsearch uses, so that it is easy to translate the Elasticsearch reference documentation at http://www.elasticsearch/guide for an API to the equivalent in this client.
This class provides the methods for document CRUD, bulk document CRUD and search. It also provides access to clients for managing indices and the cluster. Periodt. π
π₯ PREVIOUS VERSIONS OF ELASTICSEARCH π₯
This version of the client supports the Elasticsearch 7.0 branch, which is not backwards compatible with earlier branches. So don't try to make fetch happen with older stuff, bestie. π
If you need to talk to a version of Elasticsearch before 7.0.0, please install one of the following modules:
Search::Elasticsearch::Client::6_0Search::Elasticsearch::Client::5_0Search::Elasticsearch::Client::2_0Search::Elasticsearch::Client::1_0Search::Elasticsearch::Client::0_90
π CONVENTIONS π
Parameter passing
Parameters can be passed to any request method as a list or as a hash reference. The following two statements are equivalent:
$e->search( size => 10 );
$e->search({size => 10});
Path parameters
Any values that should be included in the URL path, eg "/{index}/{type}" should be passed as top level parameters:
$e->search( index => 'my_index', type => 'my_type' );
Alternatively, you can specify a "path" parameter directly:
$e->search( path => '/my_index/my_type' );
Query-string parameters
Any values that should be included in the query string should be passed as top level parameters:
$e->search( size => 10 );
If you pass in a "\%params" hash, then it will be included in the query string parameters without any error checking. The following:
$e->search( size => 10, params => { from => 6, size => 6 })
would result in this query string:
?from=6&size=10
Body parameter
The request body should be passed in the "body" key:
$e->search(
body => {
query => {...}
}
);
The body can also be a UTF8-decoded string, which will be converted into UTF-8 bytes and passed as is:
$e->indices->analyze( body => "The quick brown fox");
Boolean parameters
Elasticsearch 7.0.0 and above no longer accepts truthy and falsey values for booleans. Instead, it will accept only a JSON true or false, or the string equivalents "true" or "false".
In the Perl client, you can use the following values:
- True:
"true","\1", or aJSON::PP::Booleanobject. - False:
"false","\0", or aJSON::PP::Booleanobject.
Filter path parameter
Any API which returns a JSON body accepts a "filter_path" parameter which will filter the JSON down to only the specified paths. For instance, if you are running a search request and only want the "total" hits and the "_source" field for each hit (without the "_id", "_index" etc), you can do:
$e->search(
query => {...},
filter_paths => [ 'hits.total', 'hits.hits._source' ]
);
Ignore parameter
Normally, any HTTP status code outside the 200-299 range will result in an error being thrown. To suppress these errors, you can specify which status codes to ignore in the "ignore" parameter.
$e->indices->delete(
index => 'my_index',
ignore => 404
);
This is most useful for Missing errors, which are triggered by a 404 status code when some requested resource does not exist.
Multiple error codes can be specified with an array:
$e->indices->delete(
index => 'my_index',
ignore => [404,409]
);
π CONFIGURATION π
"bulk_helper_class"
The class to use for the "bulk_helper()" method. Defaults to Search::Elasticsearch::Client::7_0::Bulk.
"scroll_helper_class"
The class to use for the "scroll_helper()" method. Defaults to Search::Elasticsearch::Client::7_0::Scroll.
π GENERAL METHODS π
"info()"
$info = $e->info
Returns information about the version of Elasticsearch that the responding node is running.
"ping()"
$e->ping
Pings a node in the cluster and returns 1 if it receives a 200 response, otherwise it throws an error.
"indices()"
$indices_client = $e->indices;
Returns a Search::Elasticsearch::Client::7_0::Direct::Indices object which can be used for managing indices, eg creating, deleting indices, managing mapping, index settings etc.
"ingest()"
$ingest_client = $e->ingest;
Returns a Search::Elasticsearch::Client::7_0::Direct::Ingest object which can be used for managing ingest pipelines.
"cluster()"
$cluster_client = $e->cluster;
Returns a Search::Elasticsearch::Client::7_0::Direct::Cluster object which can be used for managing the cluster, eg cluster-wide settings and cluster health.
"nodes()"
$node_client = $e->nodes;
Returns a Search::Elasticsearch::Client::7_0::Direct::Nodes object which can be used to retrieve node info and stats.
"snapshot()"
$snapshot_client = $e->snapshot;
Returns a Search::Elasticsearch::Client::7_0::Direct::Snapshot object which is used for managing backup repositories and creating and restoring snapshots.
"tasks()"
$tasks_client = $e->tasks;
Returns a Search::Elasticsearch::Client::7_0::Direct::Tasks object which is used for accessing the task management API.
"cat()"
$cat_client = $e->cat;
Returns a Search::Elasticsearch::Client::7_0::Direct::Cat object which can be used to retrieve simple to read text info for debugging and monitoring an Elasticsearch cluster.
"ccr()"
$ccr_client = $e->ccr;
Returns a Search::Elasticsearch::Client::7_0::Direct::CCR object which can be used to handle cross-cluster replication requests.
"ilm()"
$ilm_client = $e->ilm;
Returns a Search::Elasticsearch::Client::7_0::Direct::ILM object which can be used to handle index lifecycle management requests.
π DOCUMENT CRUD METHODS π
okay bestie, these are the methods that let you do the classic create / index / update / delete dance on single documents. one doc at a time, very main character, no entourage. π
β¨ index() β¨
$response = $e->index(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # optional, otherwise auto-generated
body => { document } # required
);
so index() is the one you call when you wanna index a brand new document or reindex one that already exists. either way, she's ready. π
Query string parameters:
error_tracehumanif_primary_termif_seq_noop_typeparentpipelinerefreshroutingtimeoutversionversion_typewait_for_active_shards
see the index docs for the whole tea: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html
β¨ create() β¨
$response = $e->create(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
body => { document } # required
);
create() is literally index()'s twin except β and this is the important bit β she will throw a Conflict error if a document with the same index, type and id is already sitting there. no duplicates on her watch, periodt. π
ββοΈ
Query string parameters:
consistencyerror_tracehumanop_typeparentrefreshroutingtimeoutversionversion_type
see the create docs: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-create.html
β¨ get() β¨
$response = $e->get(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
);
get() goes and grabs the document with that index, type and id. and if she can't find it? she throws a Missing error. dramatic, but fair. π
Query string parameters:
_source_source_excludes_source_includeserror_tracehumanparentpreferencerealtimerefreshroutingstored_fieldsversionversion_type
see the get docs: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html
β¨ get_source() β¨
$response = $e->get_source(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
);
get_source() is get() but she skips the small talk. instead of handing you the _source field plus all the document metadata (_index, _type, etc.), she just gives you the _source field on its own β which is literally the value of the body parameter you passed to index(). minimal, focused, iconic. β¨
Query string parameters:
_source_source_excludes_source_includeserror_tracehumanparentpreferencerealtimerefreshroutingversionversion_type
see the get_source docs: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html
β¨ exists() β¨
$response = $e->exists(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
);
exists() is a yes/no girlie. she returns 1 if a document with that index, type and id is out there living her life, or an empty string if she's not. simple. π¦
Query string parameters:
_source_source_excludes_source_includeserror_tracehumanparentpreferencerealtimerefreshroutingversionversion_type
see the exists docs: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-get.html
β¨ delete() β¨
$response = $e->delete(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
);
delete() does exactly what it says on the tin β she deletes the document with that index, type and id. and if the doc isn't there to delete? Missing error, thrown right at you. π
Query string parameters:
error_tracehumanif_primary_termif_seq_noparentrefreshroutingtimeoutversionversion_typewait_for_active_shards
see the delete docs: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete.html
β¨ update() β¨
$response = $e->update(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
body => { update } # required
);
update() updates a document with the matching index, type and id β but only if it actually exists. and ngl, there's more than one way to serve this look. you can do it:
- by handing over a partial document to get merged into the existing one:
$response = $e->update(
...,
body => {
doc => { new_field => 'new_value'},
}
);
- with an inline script:
$response = $e->update(
...,
body => {
script => {
source => "ctx._source.counter += incr",
params => { incr => 6 }
}
}
);
- with an indexed script:
$response = $e->update(
...,
body => {
script => {
id => $id,
lang => 'painless',
params => { incr => 6 }
}
}
);
see indexed scripts: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_indexed_scripts
- with a script stored as a file:
$response = $e->update(
...,
body => {
script => {
file => 'counter',
lang => 'painless',
params => { incr => 6 }
}
}
);
see scripting docs: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html
Query string parameters:
_source_source_excludes_source_includeserror_tracefieldshumanif_primary_termif_seq_nolangparentrefreshretry_on_conflictroutingtimeoutversionversion_typewait_for_active_shards
see the update docs: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html
β¨ termvectors() β¨
$results = $e->termvectors(
index => $index, # required
type => $type, # required
id => $id, # optional
body => {...} # optional
)
termvectors() pulls up term and field statistics, positions, offsets and payloads for the document you point her at β as long as termvectors have actually been enabled. if they haven't? yeah, nothing to see. π
Query string parameters:
error_tracefield_statisticsfieldshumanoffsetsparentpayloadspositionspreferencerealtimeroutingterm_statisticsversionversion_type
see the termvector docs: http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-termvectors.html
π₯ BULK DOCUMENT CRUD METHODS π₯
Okay bestie, listen. The bulk document CRUD methods are the ones you use when you want to run multiple CRUD actions inside a single request. And why do we care? Because fewer network requests = way better performance. It's giving efficiency, it's giving slay. π
πΈ bulk()
$response = $e->bulk(
index => 'index_name', # required if type specified
type => 'type_name', # optional
body => [ actions ] # required
);
β¨ See Search::Elasticsearch::Client::7_0::Bulk and "bulk_helper()" for a helper module that makes bulk indexing wayyy simpler to use.
The "bulk()" method can do multiple "index()", "create()", "delete()" or "update()" actions in one single request. The "body" parameter wants an array holding the list of actions you wanna perform.
Each action is made of an initial metadata hash ref with the action type in it, plus the matching metadata, like:
{ delete => { _index => 'index', _type => 'type', _id => 123 }}
Then the "index" and "create" actions want a hashref with the document itself:
{ create => { _index => 'index', _type => 'type', _id => 123 }},
{ title => "A newly created document" }
And the "update" action wants a hashref with the update commands, like:
{ update => { _index => 'index', _type => 'type', _id => 123 }},
{ script => "ctx._source.counter+=1" }
Every action can include the same parameters you'd pass to the equivalent "index()", "create()", "delete()" or "update()" request β with one lil exception: "_index", "_type" and "_id" must be written with that leading underscore. All the other parameters can go with or without the underscore, dealer's choice. π«Ά
For instance:
$response = $e->bulk(
index => 'index_name', # default index name
type => 'type_name', # default type name
body => [
# create action
{ create => {
_index => 'not_the_default_index',
_type => 'not_the_default_type',
_id => 123
}},
{ title => 'Foo' },
# index action
{ index => { _id => 124 }},
{ title => 'Foo' },
# delete action
{ delete => { _id => 126 }},
# update action
{ update => { _id => 126 }},
{ script => "ctx._source.counter+1" }
]
);
Each action gets performed separately, periodt. If one action fails, that does not drag the others down with it. They mind their business. π
Query string parameters:
"_source""_source_excludes""_source_includes""error_trace""fields""human""pipeline""refresh""routing""timeout""wait_for_active_shards"
See the bulk docs (http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html) for more info.
π bulk_helper()
$bulk_helper = $e->bulk_helper( @args );
Returns a brand new instance of the class set in "bulk_helper_class" β which defaults to Search::Elasticsearch::Client::7_0::Bulk. Cute, right? π
π¦ mget()
$results = $e->mget(
index => 'default_index', # optional, required when type specified
type => 'default_type', # optional
body => { docs or ids } # required
);
The "mget()" method grabs multiple documents in one single request. The "body" is an array of documents to retrieve:
$results = $e->mget(
index => 'default_index',
type => 'default_type',
body => {
docs => [
{ _id => 1},
{ _id => 2, _type => 'not_the_default_type' }
]
}
);
You can also pass any of the other parameters that the "get()" request accepts. Flexible queen. π
And if you've already specified an "index" and "type", you can literally just include the "ids" of the documents you want:
$results = $e->mget(
index => 'default_index',
type => 'default_type',
body => {
ids => [ 1, 2, 3]
}
);
Query string parameters:
"_source""_source_excludes""_source_includes""error_trace""human""preference""realtime""refresh""routing""stored_fields"
See the mget docs (http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-get.html) for more info.
π mtermvectors()
$results = $e->mtermvectors(
index => $index, # required if type specified
type => $type, # optional
body => { } # optional
)
Runs multiple "termvector()" requests in a single request, like:
$results = $e->mtermvectors(
index => 'test',
body => {
docs => [
{ _type => 'test', _id => 1, fields => ['text'] },
{ _type => 'test', _id => 2, payloads => 1 },
]
}
);
Query string parameters:
"error_trace""field_statistics""fields""human""ids""offsets""parent""payloads""positions""preference""realtime""routing""term_statistics""version""version_type"
See the mtermvectors docs (http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-multi-termvectors.html) for more info.
π SEARCH METHODS π
The search methods are how you query documents in one, more, or literally all the indices and of one, more, or all types. Main character energy only. β¨
π search()
$results = $e->search(
index => 'index' | \@indices, # optional
type => 'type' | \@types, # optional
body => { search params } # optional
);
The "search()" method searches for matching documents in one or more indices. And ngl, searching a single index is just as easy as searching every single index in your cluster. It can also return aggregations (http://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations.html), highlighted snippets (http://www.elastic.co/guide/en/elasticsearch/reference/current/search-highlighting.html) and did-you-mean (http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-phrase.html) or search-as-you-type (http://www.elastic.co/guide/en/elasticsearch/reference/current/search-suggesters-completion.html) suggestions. Obsessed. π
The lite version of search (http://www.elastic.co/guide/en/elasticsearch/reference/current/search-uri-request.html) lets you drop a query string right into the "q" parameter, using the Lucene query string syntax:
$results = $e->search( q => 'title:(elasticsearch clients)');
But fr fr, the preferred way to search is using the Query DSL (http://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl.html) to build a query, then passing that "query" in the request body (http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html):
$results = $e->search(
body => {
query => {
match => { title => 'Elasticsearch clients'}
}
}
);
Query string parameters:
"_source""_source_excludes""_source_includes""allow_no_indices""allow_partial_search_results""analyze_wildcard""analyzer""batched_reduce_size""default_operator""df""docvalue_fields""error_trace""expand_wildcards""explain""from""human""ignore_throttled""ignore_unavailable""lenient""max_concurrent_shard_requests""pre_filter_shard_size""preference""q""request_cache""rest_total_hits_as_int""routing""scroll""search_type""seq_no_primary_term""size""sort""stats""stored_fields""suggest_field""suggest_mode""suggest_size""suggest_text""terminate_after""timeout""track_scores""track_total_hits""typed_keys""version"
See the search reference (http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html) for more info.
Also see "send_get_body_as" in Search::Elasticsearch::Transport. π
π count()
$results = $e->count(
index => 'index' | \@indices, # optional
type => 'type' | \@types, # optional
body => { query } # optional
)
The "count()" method returns the total count of all documents matching the query:
$results = $e->count(
body => {
query => {
match => { title => 'Elasticsearch clients' }
}
}
);
Query string parameters:
"allow_no_indices""analyze_wildcard""analyzer""default_operator""df""error_trace""expand_wildcards""human""ignore_throttled""ignore_unavailable""lenient""lowercase_expanded_terms""min_score""preference""q""routing""terminate_after"
See the count docs (http://www.elastic.co/guide/en/elasticsearch/reference/current/search-count.html) for more info.
π§ search_template()
$results = $e->search_template(
index => 'index' | \@indices, # optional
type => 'type' | \@types, # optional
body => { search params } # required
);
Perform a search by specifying a template (either predefined or defined right inside the "body") plus the parameters to use with that template, like:
$results = $e->search_template(
body => {
source => {
query => {
match => {
"{{my_field}}" => "{{my_value}}"
}
},
size => "{{my_size}}"
},
params => {
my_field => 'foo',
my_value => 'bar',
my_size => 6
}
}
);
Slay. Templates + params = iconic combo. π
See the search template docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html> for more information.
Query string parameters:
"allow_no_indices""error_trace""expand_wildcards""explain""human""ignore_throttled""ignore_unavailable""preference""profile""rest_total_hits_as_int""scroll""search_type""typed_keys"
π render_search_template()
$response = $e->render_search_template(
id => 'id', # optional
body => { template } # optional
);
Okay bestie, so this one renders the template, fills in whatever params you handed it, and gives you back the resulting JSON. It's giving very much "fill in the blanks and slay". Like this:
$results = $e->render_search_template(
body => {
source => {
query => {
match => {
"{{my_field}}" => "{{my_value}}"
}
},
size => "{{my_size}}"
},
params => {
my_field => 'foo',
my_value => 'bar',
my_size => 6
}
}
);
See the search template docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/search-template.html> for more information.
π scroll()
$results = $e->scroll(
scroll => '1m',
body => {
scroll_id => $id
}
);
So when a search() has been run with the scroll parameter, scroll() is the girl who keeps pulling more results for you until they're fully exhausted. No cap, it just keeps going till there's nothing left.
See scroll_helper() and Search::Elasticsearch::Client::7_0::Scroll for a helper utility which makes managing scroll requests much easier. (Honestly? Use the helper. It's iconic.)
Query string parameters:
"error_trace""human""rest_total_hits_as_int""scroll""scroll_id"
See the scroll docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-scroll.html> and the search_type docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/search.html/search-request-search-type.html> for more information.
π§Ή clear_scroll()
$response = $e->clear_scroll(
body => {
scroll_id => $id | \@ids # required
}
);
The clear_scroll() method can clear unfinished scroll requests, freeing up resources on the server. Basically it's the "okay we're done here, clean up after yourselves" of scroll requests π
β don't leave them hanging, it's rude to the server.
π scroll_helper()
$scroll_helper = $e->scroll_helper( @args );
Returns a new instance of the class specified in the scroll_helper_class, which defaults to Search::Elasticsearch::Client::7_0::Scroll. Your little scroll bestie, preconfigured and ready.
π msearch()
$results = $e->msearch(
index => 'default_index' | \@indices, # optional
type => 'default_type' | \@types, # optional
body => [ searches ] # required
);
The msearch() method lets you do a whole bunch of searches in a single request. Very much "one trip, many errands" energy. Similar to the bulk() request, each search request in the body consists of two hashes: the metadata hash then the search request hash (the same data that you'd specify in the body of a search() request). For instance:
$results = $e->msearch(
index => 'default_index',
type => ['default_type_1', 'default_type_2'],
body => [
# uses defaults
{},
{ query => { match_all => {} }},
# uses a custom index
{ index => 'not_the_default_index' },
{ query => { match_all => {} }}
]
);
Query string parameters:
"error_trace""human""max_concurrent_searches""max__concurrent_shard_requests""pre_filter_shard_size""rest_total_hits_as_int""search_type""typed_keys"
See the msearch docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html> for more information.
β¨ msearch_template()
$results = $e->msearch_template(
index => 'default_index' | \@indices, # optional
type => 'default_type' | \@types, # optional
body => [ search_templates ] # required
);
The msearch_template() method lets you do multiple searches in a single request, but with search templates. Same deal as bulk(): each search request in the body consists of two hashes β the metadata hash, then the search request hash (the same data that you'd specify in the body of a search() request). For instance:
$results = $e->msearch(
index => 'default_index',
type => ['default_type_1', 'default_type_2'],
body => [
# uses defaults
{},
{ source => { query => { match => { user => "{{user}}" }}} params => { user => 'joe' }},
# uses a custom index
{ index => 'not_the_default_index' },
{ source => { query => { match => { user => "{{user}}" }}} params => { user => 'joe' }},
]
);
Query string parameters:
"error_trace""human""max_concurrent_searches""rest_total_hits_as_int""search_type""typed_keys"
See the msearch-template docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html> for more information.
π‘ explain()
$response = $e->explain(
index => 'my_index', # required
type => 'my_type', # required
id => 123, # required
body => { search } # required
);
The explain() method explains why the specified document did or did not match a query, and how the relevance score was calculated. It's literally the "so WHY did this show up in my results" method β receipts, delivered. For instance:
$response = $e->explain(
index => 'my_index',
type => 'my_type',
id => 123,
body => {
query => {
match => { title => 'Elasticsearch clients' }
}
}
);
Query string parameters:
"_source""_source_excludes""_source_includes""analyze_wildcard""analyzer""default_operator""df""error_trace""human""lenient""parent""preference""q""routing""stored_fields"
See the explain docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/search-explain.html> for more information.
π¦ field_caps()
$response = $e->field_caps(
index => 'index' | \@indices, # optional
body => { filters } # optional
);
The field-caps API returns field types and abilities, merged across indices. Like a vibe check for your fields β who are you, and what can you do π
.
Query string parameters:
"allow_no_indices""error_trace""expand_wildcards""fields""human""ignore_unavailable"
See the field-caps docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/search-field-caps.html> for more information.
πΈ search_shards()
$response = $e->search_shards(
index => 'index' | \@indices, # optional
)
The search_shards() method returns information about which shards on which nodes will execute a search request. It's the "so who's actually doing the work here" of search requests, and honestly, we respect the transparency.
Query string parameters:
"allow_no_indices""error_trace""expand_wildcards""human""ignore_unavailable""local""preference""routing"
See the search-shards docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/search-shards.html> for more information.
π rank_eval()
$result = $e->rank_eval(
index => 'index' | \@indices, # optional
body => {...} # required
);
The ranking evaluation API provides a way to execute test cases to determine whether search results are improving or worsening. Yes bestie, it's the glow-up tracker for your search relevance β is it eating, or is it flopping? This method tells you.
Query string parameters:
"allow_no_indices""error_trace""expand_wildcards""filter_path""human""ignore_unavailable"
See the rank-eval docs <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-rank-eval.html> for more information.
β¨ CRUD-BY-QUERY METHODS β¨
Okay bestie, this is the section where you do CRUD but likeβ¦ by query. It's giving "bulk actions but make them β¨aestheticβ¨". π
ποΈ delete_by_query()
$response = $e->delete_by_query(
index => 'index' | \@indices, # optional
type => 'type' | \@types, # optional,
body => { delete-by-query } # required
);
The delete_by_query() method deletes all documents which match the specified query. Like, every single one that matches. Gone. Poof. π
Query string parameters:
"_source""_source_excludes""_source_includes""allow_no_indices""analyze_wildcard""analyzer""conflicts""default_operator""df""error_trace""expand_wildcards""from""human""ignore_unavailable""lenient""preference""q""refresh""request_cache""requests_per_second""routing""scroll""scroll_size""search_timeout""search_type""size""slices""sort""stats""terminate_after""version""timeout""wait_for_active_shards""wait_for_completion"
See the delete-by-query docs <https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html> for more information. π¦
π’ delete_by_query_rethrottle()
$response = $e->delete_by_query_rethrottle(
task_id => 'id' # required
requests_per_second => num
);
The delete_by_query_rethrottle() API is used to dynamically update the throtting of an existing delete-by-query request, identified by task_id. (Yes, "throtting" β that's what the original says, I don't make the rules. π«Ά)
Query string parameters:
"error_trace""filter_path""human""requests_per_second"
See the delete-by-query-rethrottle docs <https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html> for more information.
π reindex()
$response = $e->reindex(
body => { reindex } # required
);
The reindex() API is used to index documents from one index or multiple indices to a new index. It's giving "moving houses but for your docs". π¦β¨
Query string parameters:
"error_trace""human""refresh""requests_per_second""slices""timeout""wait_for_active_shards""wait_for_completion"
See the reindex docs <https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html> for more information.
π’β¨ reindex_rethrottle()
$response = $e->delete_by_query_rethrottle(
task_id => 'id', # required
requests_per_second => num
);
The reindex_rethrottle() API is used to dynamically update the throtting of an existing reindex request, identified by task_id.
Not me pointing out that the example above calls delete_by_query_rethrottle β that's literally what the page says, so I'm keeping it exactly as-is. No cap. π
Query string parameters:
"error_trace""filter_path""human""requests_per_second"
See the reindex-rethrottle docs <https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html> for more information.
π οΈ update_by_query()
$response = $e->update_by_query(
index => 'index' | \@indices, # optional
type => 'type' | \@types, # optional,
body => { update-by-query } # optional
);
The update_by_query() API is used to bulk update documents from one index or multiple indices using a script. Glow-up your whole dataset at once, periodt. π
Query string parameters:
"_source""_source_excludes""_source_includes""allow_no_indices""analyze_wildcard""analyzer""conflicts""default_operator""df""error_trace""expand_wildcards""from""human""ignore_unavailable""lenient""pipeline""preference""q""refresh""request_cache""requests_per_second""routing""scroll""scroll_size""search_timeout""search_type""size""slices""sort""stats""terminate_after""timeout""version""version_type""wait_for_active_shards""wait_for_completion"
See the update_by_query docs <https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html> for more information.
π’πΈ update_by_query_rethrottle()
$response = $e->update_by_query_rethrottle(
task_id => 'id' # required
requests_per_second => num
);
The update_by_query_rethrottle() API is used to dynamically update the throtting of an existing update-by-query request, identified by task_id.
Query string parameters:
"error_trace""filter_path""human""requests_per_second"
See the update-by-query-rethrottle docs <https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update-by-query.html> for more information.
π INDEXED SCRIPT METHODS π
Elasticsearch allows you to store scripts in the cluster state and reference them by id. The methods to manage indexed scripts are as follows β think of it like saving your fave script to the cloud so you can just @ it later. β¨
πΎ put_script()
$result = $e->put_script(
id => 'id', # required
context => $context, # optional
body => { script } # required
);
The put_script() method is used to store a script in the cluster state. For instance:
$result = $e->put_scripts(
id => 'hello_world',
body => {
script => {
lang => 'painless',
source => q(return "hello world")
}
}
);
Query string parameters:
"error_trace""human"
See the indexed scripts docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_indexed_scripts> for more.
π get_script()
$script = $e->get_script(
id => 'id', # required
);
Retrieve the indexed script from the cluster state.
Query string parameters:
"error_trace""human""master_timeout"
See the indexed scripts docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_indexed_scripts> for more.
ποΈ delete_script()
$script = $e->delete_script(
id => 'id', # required
);
Delete the indexed script from the cluster state.
Query string parameters:
"error_trace""human""master_timeout""timeout"
See the indexed scripts docs <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#_indexed_scripts> for more.
β‘ scripts_painless_execute()
$result = $e->scripts_painless_execute(
body => {...} # required
);
The Painless execute API allows an arbitrary script to be executed and a result to be returned. Just run it and see what happens, iykyk. π§
Query string parameters:
"error_trace""filter_path""human"
See the painless execution docs <https://www.elastic.co/guide/en/elasticsearch/painless/current/painless-execute-api.html> for more.
π AUTHOR π
Enrico Zimuel <enrico.zimuel@elastic.co>
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2021 by Elasticsearch BV.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
And that's a wrap on the whole page, bestie!! π This was perl v5.32.1 energy, dated 2021-10-23 β the day this little legend of a manpage was born. Go forth and query responsibly. Slay. π β¨π
π¦ where this page comes from
- ubuntu jammy: libsearch-elasticsearch-perl 7.715-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms