NAME
Search::Elasticsearch::Client::5_0::Direct - Thin client with full support for Elasticsearch 5.x APIs
VERSION
version 6.81
SYNOPSIS
Create a client:
use Search::Elasticsearch;
my $e = Search::Elasticsearch->new(
client => '5_0::Direct'
);
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;
DESCRIPTION
The Search::Elasticsearch::Client::5_0::Direct class provides the Elasticsearch 5.x compatible client returned by:
$e = Search::Elasticsearch->new(
client => "5_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 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.
PREVIOUS VERSIONS OF ELASTICSEARCH
This version of the client supports the Elasticsearch 5.0 branch, which is not backwards compatible with earlier branches.
If you need to talk to a version of Elasticsearch before 5.0.0, please install one of the following modules:
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 => 5, size => 5 })
would result in this query string:
?from=5&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");
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_path => [ '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::5_0::Bulk.
scroll_helper_class
The class to use for the "scroll_helper()" method. Defaults to Search::Elasticsearch::Client::5_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::5_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::5_0::Direct::Ingest object which can be used for managing ingest pipelines.
cluster()
$cluster_client = $e->cluster;
Returns a Search::Elasticsearch::Client::5_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::5_0::Direct::Nodes object which can be used to retrieve node info and stats.
snapshot()
$snapshot_client = $e->snapshot;
Returns a Search::Elasticsearch::Client::5_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::5_0::Direct::Tasks object which is used for accessing the task management API.
cat()
$cat_client = $e->cat;
Returns a Search::Elasticsearch::Client::5_0::Direct::Cat object which can be used to retrieve simple to read text info for debugging and monitoring an Elasticsearch cluster.
DOCUMENT CRUD METHODS
These methods allow you to perform create, index, update and delete requests for single documents:
index()
$response = $e->index(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # optional, otherwise auto-generated
body => { document } # required
);
The index()
method is used to index a new document or to reindex an existing document.
Query string parameters: error_trace
, human
, op_type
, parent
, pipeline
, refresh
, routing
, timeout
, timestamp
, ttl
, version
, version_type
, wait_for_active_shards
See the index docs for more information.
create()
$response = $e->create(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
body => { document } # required
);
The create()
method works exactly like the "index()" method, except that it will throw a Conflict
error if a document with the same index
, type
and id
already exists.
Query string parameters: consistency
, error_trace
, human
, op_type
, parent
, refresh
, routing
, timeout
, timestamp
, ttl
, version
, version_type
See the create docs for more information.
get()
$response = $e->get(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
);
The get()
method will retrieve the document with the specified index
, type
and id
, or will throw a Missing
error.
Query string parameters: _source
, _source_exclude
, _source_include
, error_trace
, human
, parent
, preference
, realtime
, refresh
, routing
, stored_fields
, version
, version_type
See the get docs for more information.
get_source()
$response = $e->get_source(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
);
The get_source()
method works just like the "get()" method except that it returns just the _source
field (the value of the body
parameter in the "index()" method) instead of returning the _source
field plus the document metadata, ie the _index
, _type
etc.
Query string parameters: _source
, _source_exclude
, _source_include
, error_trace
, human
, parent
, preference
, realtime
, refresh
, routing
, version
, version_type
See the get_source docs for more information.
exists()
$response = $e->exists(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
);
The exists()
method returns 1
if a document with the specified index
, type
and id
exists, or an empty string if it doesn't.
Query string parameters: _source
, _source_exclude
, _source_include
, error_trace
, human
, parent
, preference
, realtime
, refresh
, routing
, version
, version_type
See the exists docs for more information.
delete()
$response = $e->delete(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
);
The delete()
method will delete the document with the specified index
, type
and id
, or will throw a Missing
error.
Query string parameters: error_trace
, human
, parent
, refresh
, routing
, timeout
, version
, version_type
, wait_for_active_shards
See the delete docs for more information.
update()
$response = $e->update(
index => 'index_name', # required
type => 'type_name', # required
id => 'doc_id', # required
body => { update } # required
);
The update()
method updates a document with the corresponding index
, type
and id
if it exists. Updates can be performed either by:
providing a partial document to be merged in to the existing document:
$response = $e->update( ..., body => { doc => { new_field => 'new_value'}, } );
with an inline script:
$response = $e->update( ..., body => { script => { inline => "ctx._source.counter += incr", params => { incr => 5 } } } );
with an indexed script:
$response = $e->update( ..., body => { script => { id => $id, lang => 'painless', params => { incr => 5 } } } );
See indexed scripts for more information.
with a script stored as a file:
$response = $e->update( ..., body => { script => { file => 'counter', lang => 'painless', params => { incr => 5 } } } );
See scripting docs for more information.
Query string parameters: _source
, _source_exclude
, _source_include
, error_trace
, fields
, human
, lang
, parent
, refresh
, retry_on_conflict
, routing
, timeout
, timestamp
, ttl
, version
, version_type
, wait_for_active_shards
See the update docs for more information.
termvectors()
$results = $e->termvectors(
index => $index, # required
type => $type, # required
id => $id, # optional
body => {...} # optional
)
The termvectors()
method retrieves term and field statistics, positions, offsets and payloads for the specified document, assuming that termvectors have been enabled.
Query string parameters: error_trace
, field_statistics
, fields
, human
, offsets
, parent
, payloads
, positions
, preference
, realtime
, routing
, term_statistics
, version
, version_type
See the termvector docs for more information.
BULK DOCUMENT CRUD METHODS
The bulk document CRUD methods are used for running multiple CRUD actions within a single request. By reducing the number of network requests that need to be made, bulk requests greatly improve performance.
bulk()
$response = $e->bulk(
index => 'index_name', # required if type specified
type => 'type_name', # optional
body => [ actions ] # required
);
See Search::Elasticsearch::Client::5_0::Bulk and "bulk_helper()" for a helper module that makes bulk indexing simpler to use.
The bulk()
method can perform multiple "index()", "create()", "delete()" or "update()" actions with a single request. The body
parameter expects an array containing the list of actions to perform.
An action consists of an initial metadata hash ref containing the action type, plus the associated metadata, eg :
{ delete => { _index => 'index', _type => 'type', _id => 123 }}
The index
and create
actions then expect a hashref containing the document itself:
{ create => { _index => 'index', _type => 'type', _id => 123 }},
{ title => "A newly created document" }
And the update
action expects a hashref containing the update commands, eg:
{ update => { _index => 'index', _type => 'type', _id => 123 }},
{ script => "ctx._source.counter+=1" }
Each action can include the same parameters that you would pass to the equivalent "index()", "create()", "delete()" or "update()" request, except that _index
, _type
and _id
must be specified with the preceding underscore. All other parameters can be specified with or without the underscore.
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 => 125 }},
# update action
{ update => { _id => 126 }},
{ script => "ctx._source.counter+1" }
]
);
Each action is performed separately. One failed action will not cause the others to fail as well.
Query string parameters: _source
, _source_exclude
, _source_include
, error_trace
, fields
, human
, pipeline
, refresh
, routing
, timeout
, wait_for_active_shards
See the bulk docs for more information.
bulk_helper()
$bulk_helper = $e->bulk_helper( @args );
Returns a new instance of the class specified in the "bulk_helper_class", which defaults to Search::Elasticsearch::Client::5_0::Bulk.
mget()
$results = $e->mget(
index => 'default_index', # optional, required when type specified
type => 'default_type', # optional
body => { docs or ids } # required
);
The mget()
method will retrieve multiple documents with a single request. The body
consists of 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.
If you have specified an index
and type
, you can just include the ids
of the documents to retrieve:
$results = $e->mget(
index => 'default_index',
type => 'default_type',
body => {
ids => [ 1, 2, 3]
}
);
Query string parameters: _source
, _source_exclude
, _source_include
, error_trace
, human
, preference
, realtime
, refresh
, routing
, stored_fields
See the mget docs for more information.
mtermvectors()
$results = $e->mtermvectors(
index => $index, # required if type specified
type => $type, # optional
body => { } # optional
)
Runs multiple "termvector()" requests in a single request, eg:
$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 for more information.
SEARCH METHODS
The search methods are used for querying documents in one, more or all indices and of one, more or all types:
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. It is just as easy to search a single index as it is to search all the indices in your cluster. It can also return aggregations highlighted snippets and did-you-mean or search-as-you-type suggestions.
The lite version of search allows you to specify a query string in the q
parameter, using the Lucene query string syntax:
$results = $e->search( q => 'title:(elasticsearch clients)');
However, the preferred way to search is by using the Query DSL to create a query, and passing that query
in the request body:
$results = $e->search(
body => {
query => {
match => { title => 'Elasticsearch clients'}
}
}
);
Query string parameters: _source
, _source_exclude
, _source_include
, allow_no_indices
, analyze_wildcard
, analyzer
, batched_reduce_size
, default_operator
, df
, docvalue_fields
, error_trace
, expand_wildcards
, explain
, fielddata_fields
, from
, human
, ignore_unavailable
, lenient
, max_concurrent_shard_requests
, pre_filter_shard_size
, preference
, q
, request_cache
, routing
, scroll
, search_type
, size
, sort
, stats
, stored_fields
, suggest_field
, suggest_mode
, suggest_size
, suggest_text
, terminate_after
, timeout
, track_scores
, typed_keys
, version
See the search reference for more information.
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_unavailable
, lenient
, lowercase_expanded_terms
min_score
, preference
, q
, routing
, terminate_after
See the count docs for more information.
search_template()
$results = $e->search_template(
index => 'index' | \@indices, # optional
type => 'type' | \@types, # optional
body => { search params } # optional
);
Perform a search by specifying a template (either predefined or defined within the body
) and parameters to use with the template, eg:
$results = $e->search_template(
body => {
inline => {
query => {
match => {
"{{my_field}}" => "{{my_value}}"
}
},
size => "{{my_size}}"
},
params => {
my_field => 'foo',
my_value => 'bar',
my_size => 5
}
}
);
See the search template docs for more information.
Query string parameters: allow_no_indices
, error_trace
, expand_wildcards
, explain
, human
, ignore_unavailable
, preference
, profile
, scroll
, search_type
, typed_keys
render_search_template()
$response = $e->render_search_template(
id => 'id', # optional
body => { template } # optional
);
Renders the template, filling in the passed-in parameters and returns the resulting JSON, eg:
$results = $e->render_search_template(
body => {
inline => {
query => {
match => {
"{{my_field}}" => "{{my_value}}"
}
},
size => "{{my_size}}"
},
params => {
my_field => 'foo',
my_value => 'bar',
my_size => 5
}
}
);
See the search template docs for more information.
scroll()
$results = $e->scroll(
scroll => '1m',
body => {
scroll_id => $id
}
);
When a "search()" has been performed with the scroll
parameter, the scroll()
method allows you to keep pulling more results until the results are exhausted.
See "scroll_helper()" and Search::Elasticsearch::Client::5_0::Scroll for a helper utility which makes managing scroll requests much easier.
Query string parameters: error_trace
, human
, scroll
, scroll_id
See the scroll docs and the search_type docs 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.
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::5_0::Scroll.
msearch()
$results = $e->msearch(
index => 'default_index' | \@indices, # optional
type => 'default_type' | \@types, # optional
body => [ searches ] # required
);
The msearch()
method allows you to perform multiple searches in a single request. 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
, pre_filter_shard_size
, search_type
, typed_keys
See the msearch docs 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 allows you to perform multiple searches in a single request using search templates. 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
{},
{ inline => { query => { match => { user => "{{user}}" }}} params => { user => 'joe' }},
# uses a custom index
{ index => 'not_the_default_index' },
{ inline => { query => { match => { user => "{{user}}" }}} params => { user => 'joe' }},
]
);
Query string parameters: error_trace
, human
, max_concurrent_searches
, search_type
, typed_keys
See the msearch-template docs 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. For instance:
$response = $e->explain(
index => 'my_index',
type => 'my_type',
id => 123,
body => {
query => {
match => { title => 'Elasticsearch clients' }
}
}
);
Query string parameters: _source
, _source_exclude
, _source_include
, analyze_wildcard
, analyzer
, default_operator
, df
, error_trace
, human
, lenient
, parent
, preference
, q
, routing
, stored_fields
See the explain docs 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.
Query string parameters: allow_no_indices
, error_trace
, expand_wildcards
, fields
, human
, ignore_unavailable
See the field-caps docs for more information.
field_stats()
$response = $e->field_stats(
index => 'index' | \@indices, # optional
fields => 'field' | \@fields, # optional
level => 'cluster' | 'indices', # optional
body => { filters } # optional
);
The field-stats
API returns statistical properties of a field (such as min and max values) without executing a search.
Query string parameters: allow_no_indices
, error_trace
, expand_wildcards
, fields
, human
, ignore_unavailable
, level
See the field-stats docs for more information.
search_shards()
$response = $e->search_shards(
index => 'index' | \@indices, # optional
type => 'type' | \@types, # optional
)
The search_shards()
method returns information about which shards on which nodes will execute a search request.
Query string parameters: allow_no_indices
, error_trace
, expand_wildcards
, human
, ignore_unavailable
, local
, preference
, routing
See the search-shards docs for more information.
CRUD-BY-QUERY METHODS
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.
Query string parameters: _source
, _source_exclude
, _source_include
, 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 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.
Query string parameters: error_trace
, human
, refresh
, requests_per_second
, slices
, timeout
, wait_for_active_shards
, wait_for_completion
See the reindex docs 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.
Query string parameters: _source
, _source_exclude
, _source_include
, 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 for more information.
reindex_rethrottle
$response = $e->reindex_rethrottle(
task_id => 'task_id', # required
requests_per_second => $req_per_second
);
The reindex_rethrottle()
API is used to dynamically update the throtting of an existing reindex request, identified by task_id
.
Query string parameters: error_trace
, human
, requests_per_second
See the reindex docs for more information.
PERCOLATION METHODS
percolate()
$results = $e->percolate(
index => 'my_index', # required
type => 'my_type', # required
body => { percolation } # required
);
Percolation is search inverted: instead of finding docs which match a particular query, it finds queries which match a particular document, eg for alert-me-when functionality.
The percolate()
method runs a percolation request to find the queries matching a particular document. In the body
you should pass the _source
field of the document under the doc
key:
$results = $e->percolate(
index => 'my_index',
type => 'my_type',
body => {
doc => {
title => 'Elasticsearch rocks'
}
}
);
Query string parameters: allow_no_indices
, error_trace
, expand_wildcards
, human
, ignore_unavailable
, percolate_format
, percolate_index
, percolate_preference
, percolate_routing
, percolate_type
, preference
, routing
, version
, version_type
See the percolate docs for more information.
count_percolate()
$results = $e->count_percolate(
index => 'my_index', # required
type => 'my_type', # required
body => { percolation } # required
);
The "count_percolate()" request works just like the "percolate()" request except that it returns a count of all matching queries, instead of the queries themselves.
$results = $e->count_percolate(
index => 'my_index',
type => 'my_type',
body => {
doc => {
title => 'Elasticsearch rocks'
}
}
);
Query string parameters: allow_no_indices
, error_trace
, expand_wildcards
, human
, ignore_unavailable
, percolate_index
, percolate_type
, preference
, routing
, version
, version_type
See the percolate docs for more information.
mpercolate()
$results = $e->mpercolate(
index => 'my_index', # required if type
type => 'my_type', # optional
body => [ percolation requests ] # required
);
Multi-percolation allows multiple "percolate()" requests to be run in a single request.
$results = $e->mpercolate(
index => 'my_index',
type => 'my_type',
body => [
# first request
{ percolate => {
index => 'twitter',
type => 'tweet'
}},
{ doc => {message => 'some_text' }},
# second request
{ percolate => {
index => 'twitter',
type => 'tweet',
id => 1
}},
{},
]
);
Query string parameters: allow_no_indices
, error_trace
, expand_wildcards
, human
, ignore_unavailable
See the mpercolate docs for more information.
suggest()
$results = $e->suggest(
index => 'index' | \@indices, # optional
body => { suggest request } # required
);
The suggest()
method is used to run did-you-mean or search-as-you-type suggestion requests, which can also be run as part of a "search()" request.
$results = $e->suggest(
index => 'my_index',
body => {
my_suggestions => {
phrase => {
text => 'johnny walker',
field => 'title'
}
}
}
);
Query string parameters: allow_no_indices
, error_trace
, expand_wildcards
, human
, ignore_unavailable
, preference
, routing
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:
put_script()
$result = $e->put_script(
lang => 'lang', # required
id => 'id', # required
body => { script } # required
);
The put_script()
method is used to store a script in the cluster state. For instance:
$result = $e->put_scripts(
lang => 'painless',
id => 'hello_world',
body => {
script => {
lang => 'painless',
source => q(return "hello world")
}
}
);
Query string parameters: error_trace
, human
, master_timeout
, timeout
See the indexed scripts docs for more.
get_script()
$script = $e->get_script(
lang => 'lang', # required
id => 'id', # required
);
Retrieve the indexed script from the cluster state.
Query string parameters: error_trace
, human
See the indexed scripts docs for more.
delete_script()
$script = $e->delete_script(
lang => 'lang', # required
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 for more.
INDEXED SEARCH TEMPLATE METHODS
Mustache templates can be used to create search requests. These templates can be stored in the cluster state and retrieved by ID. The methods to manage indexed scripts are as follows:
put_template()
$result = $e->put_template(
id => 'id', # required
body => { template } || "template" # required
);
The put_template()
method is used to store a template in the cluster state. For instance:
$result = $e->put_template(
id => 'hello_world',
body => {
template => {
query => {
match => {
title => "hello world"
}
}
}
}
);
Query string parameters: error_trace
, human
See the indexed search template docs for more.
get_template()
$script = $e->get_template(
id => 'id', # required
);
Retrieve the indexed template from the cluster state.
Query string parameters: error_trace
, human
See the indexed search template docs for more.
delete_template()
$script = $e->delete_template(
id => 'id', # required
);
Delete the indexed template from the cluster state.
Query string parameters: error_trace
, human
See the indexed search template docs 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