1:- module(plasticsearch, [
    2    plasticsearch/1,    % -Ps
    3    plasticsearch/2,    % -Ps, +Options
    4    plasticsearch/3,    % -Ps, +Hosts, +Options
    5    destroy/1,          % +Ps
    6    ping/1,             % +Ps
    7    ping/2,             % +Ps, +Params
    8    info/2,             % +Ps, -Reply
    9    info/3,             % +Ps, +Params, -Reply
   10    create/6,           % +Ps, +Index, +DocType, +ID, +Body, -Reply
   11    create/7,           % +Ps, +Index, +DocType, +ID, +Params, +Body, -Reply
   12    index/6,            % +Ps, +Index, +DocType, +ID, +Body, -Reply
   13    index/7,            % +Ps, +Index, +DocType, +ID, +Params, +Body, -Reply
   14    exists/4,           % +Ps, +Index, +DocType, +ID
   15    exists/5,           % +Ps, +Index, +DocType, +ID, +Params
   16    get/5,              % +Ps, +Index, +DocType, +ID, -Reply
   17    get/6,              % +Ps, +Index, +DocType, +ID, +Params, -Reply
   18    get_source/5,       % +Ps, +Index, +DocType, +ID, -Reply
   19    get_source/6,       % +Ps, +Index, +DocType, +ID, +Params, -Reply
   20    mget/5,             % +Ps, +Index, +DocType, +Body, -Reply
   21    mget/6,             % +Ps, +Index, +DocType, +Params, +Body, -Reply
   22    update/6,           % +Ps, +Index, +DocType, +ID, +Body, -Reply
   23    update/7,           % +Ps, +Index, +DocType, +ID, +Params, +Body, -Reply
   24    search/5,           % +Ps, +Index, +DocType, +Body, -Reply
   25    search/6,           % +Ps, +Index, +DocType, +Params, +Body, -Reply
   26    search_shards/4,    % +Ps, +Index, +DocType, -Reply
   27    search_shards/5,    % +Ps, +Index, +DocType, +Params, -Reply
   28    search_template/5,  % +Ps, +Index, +DocType, +Body, -Reply
   29    search_template/6,  % +Ps, +Index, +DocType, +Params, +Body, -Reply
   30    explain/6,          % +Ps, +Index, +DocType, +ID, +Body, -Reply
   31    explain/7,          % +Ps, +Index, +DocType, +ID, +Params, +Body, -Reply
   32    scroll/3,           % +Ps, ID, -Reply
   33    scroll/4,           % +Ps, ID, +Params, -Reply
   34    clear_scroll/4,     % +Ps, ID, +Body, -Reply
   35    clear_scroll/5,     % +Ps, ID, +Params, +Body, -Reply
   36    delete/5,           % +Ps, +Index, +DocType, +ID, -Reply
   37    delete/6,           % +Ps, +Index, +DocType, +ID, +Params, -Reply
   38    count/5,            % +Ps, +Index, +DocType, +Body, -Reply
   39    count/6,            % +Ps, +Index, +DocType, +Params, +Body, -Reply
   40    bulk/5,             % +Ps, +Index, +DocType, +Body, -Reply
   41    bulk/6,             % +Ps, +Index, +DocType, +Params, +Body, -Reply
   42    msearch/5,          % +Ps, +Index, +DocType, +Body, -Reply
   43    msearch/6,          % +Ps, +Index, +DocType, +Params, +Body, -Reply
   44    delete_by_query/5,  % +Ps, +Index, +DocType, +Body, -Reply
   45    delete_by_query/6,  % +Ps, +Index, +DocType, +Params, +Body, -Reply
   46    suggest/4,          % +Ps, +Index, +Body, -Reply
   47    suggest/5,          % +Ps, +Index, +Params, +Body, -Reply
   48    percolate/6,        % +Ps, +Index, +DocType, +ID, +Body, -Reply
   49    percolate/7,        % +Ps, +Index, +DocType, +ID, +Params, +Body, -Reply
   50    mpercolate/5,       % +Ps, +Index, +DocType, +Body, -Reply
   51    mpercolate/6,       % +Ps, +Index, +DocType, +Params, +Body, -Reply
   52    count_percolate/6,  % +Ps, +Index, +DocType, +ID, +Body, -Reply
   53    count_percolate/7,  % +Ps, +Index, +DocType, +ID, +Params, +Body, -Reply
   54    mlt/6,              % +Ps, +Index, +DocType, +ID, +Body, -Reply
   55    mlt/7,              % +Ps, +Index, +DocType, +ID, +Params, +Body, -Reply
   56    termvectors/6,      % +Ps, +Index, +DocType, +ID, +Body, -Reply
   57    termvectors/7,      % +Ps, +Index, +DocType, +ID, +Params, +Body, -Reply
   58    termvector/6,       % +Ps, +Index, +DocType, +ID, +Body, -Reply
   59    termvector/7,       % +Ps, +Index, +DocType, +ID, +Params, +Body, -Reply
   60    mtermvectors/5,     % +Ps, +Index, +DocType, +Body, -Reply
   61    mtermvectors/6,     % +Ps, +Index, +DocType, +Params, +Body, -Reply
   62    benchmark/5,        % +Ps, +Index, +DocType, +Body, -Reply
   63    benchmark/6,        % +Ps, +Index, +DocType, +Params, +Body, -Reply
   64    abort_benchmark/3,  % +Ps, +Name, -Reply
   65    abort_benchmark/4,  % +Ps, +Name, +Params, -Reply
   66    list_benchmark/4,   % +Ps, +Index, +DocType, -Reply
   67    list_benchmark/5,   % +Ps, +Index, +DocType, +Params, -Reply
   68    put_script/5,       % +Ps, +Lang, +ID, +Body, -Reply
   69    put_script/6,       % +Ps, +Lang, +ID, +Params, +Body, -Reply
   70    get_script/4,       % +Ps, +Lang, +ID, -Reply
   71    get_script/5,       % +Ps, +Lang, +ID, +Params, -Reply
   72    delete_script/4,    % +Ps, +Lang, +ID, -Reply
   73    delete_script/5,    % +Ps, +Lang, +ID, +Params, -Reply
   74    put_template/4,     % +Ps, +ID, +Body, -Reply
   75    put_template/5,     % +Ps, +ID, +Params, +Body, -Reply
   76    get_template/3,     % +Ps, +ID, -Reply
   77    get_template/4,     % +Ps, +ID, +Params, -Reply
   78    delete_template/3,  % +Ps, +ID, -Reply
   79    delete_template/4,  % +Ps, +ID, +Params, -Reply
   80    search_exists/5,    % +Ps, +Index, +DocType, +Body, -Reply
   81    search_exists/6     % +Ps, +Index, +DocType, +Params, +Body, -Reply
   82]).

Elasticsearch Prolog APIs.

This is basically a Prolog version of Elasticsearch Python APIs.

author
- Hongxin Liang
See also
- https://github.com/elastic/elasticsearch-py
license
- Apache License Version 2.0
To be done
- Sniffing is not supported. */
   94:- use_module(library(uuid)).   95:- use_module(library(uri)).   96:- use_module(library(http/json)).   97
   98:- use_module(registry).   99
  100:- use_module(cluster, []).  101:- use_module(nodes, []).  102:- use_module(indices, []).  103:- use_module(snapshots, []).  104
  105:- use_module(transport).  106:- use_module(util).
 plasticsearch(-Ps) is det
 plasticsearch(-Ps, +Options) is det
 plasticsearch(-Ps, +Hosts, +Options) is det
Create a new Plasticsearch instance.

Default options are:

dead_timeout(60)
retry_on_timeout(false)
max_retries(3)
timeout_cutoff(5)
random_selector(false)
retry_on_status([503, 504])

If no Hosts are given, http://localhost:9200 will be used by default. If only hostname is provided, port 9200 will be used and http will be assumed. Otherwise = uri_components(Scheme, Authority, Path, Search, Fragment) = can be used for fine-grained configuration.

  130plasticsearch(Ps) :-
  131    plasticsearch(Ps, []).
  132
  133plasticsearch(Ps, Options) :-
  134    uuid(Ps),
  135    uri_components('http://localhost:9200', NormalizedHost),
  136    fill_options(Options, FullOptions),
  137    new(Ps, _{id:Ps, hosts:[NormalizedHost], options:FullOptions}).
  138
  139plasticsearch(Ps, Hosts, Options) :-
  140    uuid(Ps),
  141    (   is_list(Hosts)
  142    ->  Hosts1 = Hosts
  143    ;   Hosts1 = [Hosts]
  144    ),
  145    normalize_hosts(Hosts1, NormalizedHosts),
  146    fill_options(Options, FullOptions),
  147    new(Ps, _{id:Ps, hosts:NormalizedHosts, options:FullOptions}).
  148
  149normalize_hosts([], []) :- !.
  150
  151normalize_hosts([H|T], NormalizedHosts) :-
  152    atom(H), !,
  153    normalize_hosts(T, NormalizedHosts0),
  154    (   sub_atom_icasechk(H, _, '://')
  155    ->  Host = H
  156    ;   atomic_list_concat(['http://', H, :, 9200], Host)
  157    ),
  158    uri_components(Host, NormalizedHost),
  159    NormalizedHosts = [NormalizedHost|NormalizedHosts0].
  160
  161normalize_hosts([H|T], NormalizedHosts) :-
  162    compound_name_arity(H, uri_components, 5), !,
  163    normalize_hosts(T, NormalizedHosts0),
  164    NormalizedHosts = [H|NormalizedHosts0].
  165
  166fill_options(Options, FullOptions) :-
  167    fill_options0([
  168            dead_timeout(60),
  169            retry_on_timeout(false),
  170            max_retries(3),
  171            timeout_cutoff(5),
  172            random_selector(false),
  173            retry_on_status([503, 504])
  174        ], Options, FullOptions).
  175
  176fill_options0([], OldOptions, OldOptions) :- !.
  177fill_options0([H|T], OldOptions, NewOptions) :-
  178    fill_options0(T, OldOptions, NewOptions0),
  179    H =.. [Name, _],
  180    ToCheck =.. [Name, _],
  181    (   memberchk(ToCheck, NewOptions0)
  182    ->  NewOptions = NewOptions0
  183    ;   NewOptions = [H|NewOptions0]
  184    ).
 destroy(+Ps) is det
Destory a Plasticsearch instance.
  190destroy(Ps) :-
  191    ignore(delete(Ps)).
 ping(+Ps) is semidet
 ping(+Ps, +Params) is semidet
Returns True if the cluster is up, False otherwise.
  198ping(Ps) :-
  199    ping(Ps, _{}).
  200
  201ping(Ps, Params) :-
  202    (   catch(perform_request(Ps, head, /, Params, _, _), E, true)
  203    ->  (   var(E)
  204        ->  true
  205        )
  206    ).
 info(+Ps, -Reply) is semidet
 info(+Ps, +Params, -Reply) is semidet
Get the basic info from the current cluster.
  213info(Ps, Reply) :-
  214    info(Ps, _{}, Reply).
  215
  216info(Ps, Params, Reply) :-
  217    perform_request(Ps, get, /, Params, _, Reply).
 create(+Ps, +Index, +DocType, +ID, +Body, -Reply) is semidet
 create(+Ps, +Index, +DocType, +ID, +Params, +Body, -Reply) is semidet
Adds a typed document in a specific index, making it searchable. Behind the scenes this predicate calls index/7 with = op_type=create = as additional parameter. See here.
  227create(Ps, Index, DocType, ID, Body, Reply) :-
  228    create(Ps, Index, DocType, ID, _{}, Body, Reply).
  229
  230create(Ps, Index, DocType, ID, Params, Body, Reply) :-
  231    put_dict([op_type=create], Params, NewParams),
  232    index(Ps, Index, DocType, ID, NewParams, Body, Reply).
 index(+Ps, +Index, +DocType, +ID, +Body, -Reply) is semidet
 index(+Ps, +Index, +DocType, +ID, +Params, +Body, -Reply) is semidet
Adds or updates a typed document in a specific index, making it searchable. See here.
  240index(Ps, Index, DocType, ID, Body, Reply) :-
  241    index(Ps, Index, DocType, ID, _{}, Body, Reply).
  242
  243index(Ps, Index, DocType, ID, Params, Body, Reply) :-
  244    forall(member(Value-Name, [Index-index, DocType-doc_type, Body-body]), non_empty(Value, Name)),
  245    (   non_empty(ID, _, false)
  246    ->  Method = put
  247    ;   Method = post
  248    ),
  249    make_context([Index, DocType, ID], Context),
  250    perform_request(Ps, Method, Context, Params, Body, _, Reply).
 exists(+Ps, +Index, +DocType, +ID) is semidet
 exists(+Ps, +Index, +DocType, +ID, +Params) is semidet
Returns a boolean indicating whether or not given document exists in Elasticsearch. See here.
  258exists(Ps, Index, DocType, ID) :-
  259    exists(Ps, Index, DocType, ID, _{}).
  260
  261exists(Ps, Index, DocType, ID, Params) :-
  262    forall(member(Value-Name, [Index-index, DocType-doc_type, ID-id]), non_empty(Value, Name)),
  263    make_context([Index, DocType, ID], Context),
  264    (   catch(perform_request(Ps, head, Context, Params, _, _), E, true)
  265    ->  (   var(E)
  266        ->  true
  267        ;   E = plasticsearch_exception(404, _)
  268        )
  269    ).
 get(+Ps, +Index, +DocType, +ID, -Reply) is semidet
 get(+Ps, +Index, +DocType, +ID, +Params, -Reply) is semidet
Get a typed document from the index based on its id. See here.
  277get(Ps, Index, DocType, ID, Reply) :-
  278    get(Ps, Index, DocType, ID, _{}, Reply).
  279
  280get(Ps, Index, DocType, ID, Params, Reply) :-
  281    forall(member(Value-Name, [Index-index, DocType-doc_type, ID-id]), non_empty(Value, Name)),
  282    make_context([Index, DocType, ID], Context),
  283    perform_request(Ps, get, Context, Params, _, Reply).
 get_source(+Ps, +Index, +DocType, +ID, -Reply) is semidet
 get_source(+Ps, +Index, +DocType, +ID, +Params, -Reply) is semidet
Get the source of a document by it's index, type and id. See here.
  291get_source(Ps, Index, DocType, ID, Reply) :-
  292    get_source(Ps, Index, DocType, ID, _{}, Reply).
  293
  294get_source(Ps, Index, DocType, ID, Params, Reply) :-
  295    forall(member(Value-Name, [Index-index, DocType-doc_type, ID-id]), non_empty(Value, Name)),
  296    make_context([Index, DocType, ID, '_source'], Context),
  297    perform_request(Ps, get, Context, Params, _, Reply).
 mget(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 mget(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
Get multiple documents based on an index, type (optional) and ids. See here.
  305mget(Ps, Index, DocType, Body, Reply) :-
  306    mget(Ps, Index, DocType, _{}, Body, Reply).
  307
  308mget(Ps, Index, DocType, Params, Body, Reply) :-
  309    non_empty(Body, body),
  310    make_context([Index, DocType, '_mget'], Context),
  311    perform_request(Ps, get, Context, Params, Body, _, Reply).
 update(+Ps, +Index, +DocType, +ID, +Body, -Reply) is semidet
 update(+Ps, +Index, +DocType, +ID, +Params, +Body, -Reply) is semidet
Update a document based on a script or partial data provided. See here.
  319update(Ps, Index, DocType, ID, Body, Reply) :-
  320    update(Ps, Index, DocType, ID, _{}, Body, Reply).
  321
  322update(Ps, Index, DocType, ID, Params, Body, Reply) :-
  323    forall(member(Value-Name, [Index-index, DocType-doc_type, ID-id]), non_empty(Value, Name)),
  324    make_context([Index, DocType, ID, '_update'], Context),
  325    perform_request(Ps, post, Context, Params, Body, _, Reply).
 search(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 search(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
Execute a search query and get back search hits that match the query. See here.
  333search(Ps, Index, DocType, Body, Reply) :-
  334    search(Ps, Index, DocType, _{}, Body, Reply).
  335
  336search(Ps, Index, DocType, Params, Body, Reply) :-
  337    (   Index = '', DocType \= ''
  338    ->  Index1 = '_all'
  339    ;   Index1 = Index
  340    ),
  341    make_context([Index1, DocType, '_search'], Context),
  342    perform_request(Ps, get, Context, Params, Body, _, Reply).
 search_shards(+Ps, +Index, +DocType, -Reply) is semidet
 search_shards(+Ps, +Index, +DocType, +Params, -Reply) is semidet
The search shards api returns the indices and shards that a search request would be executed against. This can give useful feedback for working out issues or planning optimizations with routing and shard preferences. See here.
  352search_shards(Ps, Index, DocType, Reply) :-
  353    search_shards(Ps, Index, DocType, _{}, Reply).
  354
  355search_shards(Ps, Index, DocType, Params, Reply) :-
  356    make_context([Index, DocType, '_search_shards'], Context),
  357    perform_request(Ps, get, Context, Params, _, Reply).
 search_template(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 search_template(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
A query that accepts a query template and a map of key/value pairs to fill in template parameters. See here.
  366search_template(Ps, Index, DocType, Body, Reply) :-
  367    search_template(Ps, Index, DocType, _{}, Body, Reply).
  368
  369search_template(Ps, Index, DocType, Params, Body, Reply) :-
  370    make_context([Index, DocType, '_search', 'template'], Context),
  371    perform_request(Ps, get, Context, Params, Body, _, Reply).
 explain(+Ps, +Index, +DocType, +ID, +Body, -Reply) is semidet
 explain(+Ps, +Index, +DocType, +ID, +Params, +Body, -Reply) is semidet
The explain api computes a score explanation for a query and a specific document. This can give useful feedback whether a document matches or didn't match a specific query. See here.
  381explain(Ps, Index, DocType, ID, Body, Reply) :-
  382    explain(Ps, Index, DocType, ID, _{}, Body, Reply).
  383
  384explain(Ps, Index, DocType, ID, Params, Body, Reply) :-
  385    forall(member(Value-Name, [Index-index, DocType-doc_type, ID-id]), non_empty(Value, Name)),
  386    make_context([Index, DocType, ID, '_explain'], Context),
  387    perform_request(Ps, get, Context, Params, Body, _, Reply).
 scroll(+Ps, +ID, -Reply) is semidet
 scroll(+Ps, +ID, +Params, -Reply) is semidet
Scroll a search request created by specifying the scroll parameter. See here.
  395scroll(Ps, ID, Reply) :-
  396    scroll(Ps, ID, _{}, Reply).
  397
  398scroll(Ps, ID, Params, Reply) :-
  399    perform_request(Ps, get, '/_search/scroll', Params, ID, _, Reply).
 clear_scroll(+Ps, +ID, +Body, -Reply) is semidet
 clear_scroll(+Ps, +ID, +Params, +Body, -Reply) is semidet
Clear the scroll request created by specifying the scroll parameter to search. See here.
  408clear_scroll(Ps, ID, Body, Reply) :-
  409    clear_scroll(Ps, ID, _{}, Body, Reply).
  410
  411clear_scroll(Ps, ID, Params, Body, Reply) :-
  412    (   var(Body), ID = ''
  413    ->  ID1 = '_all'
  414    ;   ID1 = ID
  415    ),
  416    make_context(['_search', 'scroll', ID1], Context),
  417    perform_request(Ps, delete, Context, Params, Body, _, Reply).
 delete(+Ps, +Index, +DocType, +ID, -Reply) is semidet
 delete(+Ps, +Index, +DocType, +ID, +Params, -Reply) is semidet
Delete a typed JSON document from a specific index based on its id. See here.
  425delete(Ps, Index, DocType, ID, Reply) :-
  426    delete(Ps, Index, DocType, ID, _{}, Reply).
  427
  428delete(Ps, Index, DocType, ID, Params, Reply) :-
  429    forall(member(Value-Name, [Index-index, DocType-doc_type, ID-id]), non_empty(Value, Name)),
  430    make_context([Index, DocType, ID], Context),
  431    perform_request(Ps, delete, Context, Params, _, Reply).
 count(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 count(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
Execute a query and get the number of matches for that query. See here.
  439count(Ps, Index, DocType, Body, Reply) :-
  440    count(Ps, Index, DocType, _{}, Body, Reply).
  441
  442count(Ps, Index, DocType, Params, Body, Reply) :-
  443    (   Index = '', DocType \= ''
  444    ->  Index1 = '_all'
  445    ;   Index1 = Index
  446    ),
  447    make_context([Index1, DocType, '_count'], Context),
  448    perform_request(Ps, get, Context, Params, Body, _, Reply).
 bulk(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 bulk(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
Perform many index/delete operations in a single API call. See here.
  456bulk(Ps, Index, DocType, Body, Reply) :-
  457    bulk(Ps, Index, DocType, _{}, Body, Reply).
  458
  459bulk(Ps, Index, DocType, Params, Body, Reply) :-
  460    non_empty(Body, body),
  461    make_context([Index, DocType, '_bulk'], Context),
  462    bulk_body(Body, BulkBody),
  463    perform_request(Ps, post, Context, Params, BulkBody, _, Reply).
 msearch(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 msearch(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
Execute several search requests within the same API. See here.
  471msearch(Ps, Index, DocType, Body, Reply) :-
  472    msearch(Ps, Index, DocType, _{}, Body, Reply).
  473
  474msearch(Ps, Index, DocType, Params, Body, Reply) :-
  475    non_empty(Body, body),
  476    make_context([Index, DocType, '_msearch'], Context),
  477    bulk_body(Body, BulkBody),
  478    perform_request(Ps, get, Context, Params, BulkBody, _, Reply).
 delete_by_query(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 delete_by_query(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
Delete documents from one or more indices and one or more types based on a query. See here.
  486delete_by_query(Ps, Index, DocType, Body, Reply) :-
  487    delete_by_query(Ps, Index, DocType, _{}, Body, Reply).
  488
  489delete_by_query(Ps, Index, DocType, Params, Body, Reply) :-
  490    non_empty(Index, index),
  491    make_context([Index, DocType, '_query'], Context),
  492    perform_request(Ps, delete, Context, Params, Body, _, Reply).
 suggest(+Ps, +Index, +Body, -Reply) is semidet
 suggest(+Ps, +Index, +Params, +Body, -Reply) is semidet
The suggest feature suggests similar looking terms based on a provided text by using a suggester. See here.
  501suggest(Ps, Index, Body, Reply) :-
  502    suggest(Ps, Index, _{}, Body, Reply).
  503
  504suggest(Ps, Index, Params, Body, Reply) :-
  505    non_empty(Body, body),
  506    make_context([Index, '_suggest'], Context),
  507    perform_request(Ps, post, Context, Params, Body, _, Reply).
 percolate(+Ps, +Index, +DocType, +ID, +Body, -Reply) is semidet
 percolate(+Ps, +Index, +DocType, +ID, +Params, +Body, -Reply) is semidet
The percolator allows to register queries against an index, and then send percolate requests which include a doc, and getting back the queries that match on that doc out of the set of registered queries. See here.
  517percolate(Ps, Index, DocType, ID, Body, Reply) :-
  518    percolate(Ps, Index, DocType, ID, _{}, Body, Reply).
  519
  520percolate(Ps, Index, DocType, ID, Params, Body, Reply) :-
  521    forall(member(Value-Name, [Index-index, DocType-doc_type]), non_empty(Value, Name)),
  522    make_context([Index, DocType, ID, '_percolate'], Context),
  523    perform_request(Ps, get, Context, Params, Body, _, Reply).
 mpercolate(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 mpercolate(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
The percolator allows to register queries against an index, and then send percolate requests which include a doc, and getting back the queries that match on that doc out of the set of registered queries. See here.
  533mpercolate(Ps, Index, DocType, Body, Reply) :-
  534    mpercolate(Ps, Index, DocType, _{}, Body, Reply).
  535
  536mpercolate(Ps, Index, DocType, Params, Body, Reply) :-
  537    non_empty(Body, body),
  538    make_context([Index, DocType, '_mpercolate'], Context),
  539    bulk_body(Body, BulkBody),
  540    perform_request(Ps, get, Context, Params, BulkBody, _, Reply).
 count_percolate(+Ps, +Index, +DocType, +ID, +Body, -Reply) is semidet
 count_percolate(+Ps, +Index, +DocType, +ID, +Params, +Body, -Reply) is semidet
The percolator allows to register queries against an index, and then send percolate requests which include a doc, and getting back the queries that match on that doc out of the set of registered queries. See here.
  550count_percolate(Ps, Index, DocType, ID, Body, Reply) :-
  551    count_percolate(Ps, Index, DocType, ID, _{}, Body, Reply).
  552
  553count_percolate(Ps, Index, DocType, ID, Params, Body, Reply) :-
  554    forall(member(Value-Name, [Index-index, DocType-doc_type]), non_empty(Value, Name)),
  555    make_context([Index, DocType, ID, '_percolate', count], Context),
  556    perform_request(Ps, get, Context, Params, Body, _, Reply).
 mlt(+Ps, +Index, +DocType, +ID, +Body, -Reply) is semidet
 mlt(+Ps, +Index, +DocType, +ID, +Params, +Body, -Reply) is semidet
Get documents that are "like" a specified document. See here.
  564mlt(Ps, Index, DocType, ID, Body, Reply) :-
  565    mlt(Ps, Index, DocType, ID, _{}, Body, Reply).
  566
  567mlt(Ps, Index, DocType, ID, Params, Body, Reply) :-
  568    forall(member(Value-Name, [Index-index, DocType-doc_type, ID-id]), non_empty(Value, Name)),
  569    make_context([Index, DocType, ID, '_mlt'], Context),
  570    perform_request(Ps, get, Context, Params, Body, _, Reply).
 termvectors(+Ps, +Index, +DocType, +ID, +Body, -Reply) is semidet
 termvectors(+Ps, +Index, +DocType, +ID, +Params, +Body, -Reply) is semidet
Returns information and statistics on terms in the fields of a particular document. The document could be stored in the index or artificially provided by the user (Added in 1.4). Note that for documents stored in the index, this is a near realtime API as the term vectors are not available until the next refresh. See here.
  582termvectors(Ps, Index, DocType, ID, Body, Reply) :-
  583    termvectors(Ps, Index, DocType, ID, _{}, Body, Reply).
  584
  585termvectors(Ps, Index, DocType, ID, Params, Body, Reply) :-
  586    forall(member(Value-Name, [Index-index, DocType-doc_type, ID-id]), non_empty(Value, Name)),
  587    make_context([Index, DocType, ID, '_termvectors'], Context),
  588    perform_request(Ps, get, Context, Params, Body, _, Reply).
 termvector(+Ps, +Index, +DocType, +ID, +Body, -Reply) is semidet
 termvector(+Ps, +Index, +DocType, +ID, +Params, +Body, -Reply) is semidet
Returns information and statistics on terms in the fields of a particular document. The document could be stored in the index or artificially provided by the user (Added in 1.4). Note that for documents stored in the index, this is a near realtime API as the term vectors are not available until the next refresh. See here.
  600termvector(Ps, Index, DocType, ID, Body, Reply) :-
  601    termvector(Ps, Index, DocType, ID, _{}, Body, Reply).
  602
  603termvector(Ps, Index, DocType, ID, Params, Body, Reply) :-
  604    forall(member(Value-Name, [Index-index, DocType-doc_type, ID-id]), non_empty(Value, Name)),
  605    make_context([Index, DocType, ID, '_termvector'], Context),
  606    perform_request(Ps, get, Context, Params, Body, _, Reply).
 mtermvectors(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 mtermvectors(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
Multi termvectors API allows to get multiple termvectors based on an index, type and id. See here.
  615mtermvectors(Ps, Index, DocType, Body, Reply) :-
  616    mtermvectors(Ps, Index, DocType, _{}, Body, Reply).
  617
  618mtermvectors(Ps, Index, DocType, Params, Body, Reply) :-
  619    make_context([Index, DocType, '_mtermvectors'], Context),
  620    perform_request(Ps, get, Context, Params, Body, _, Reply).
 benchmark(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 benchmark(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
The benchmark API provides a standard mechanism for submitting queries and measuring their performance relative to one another. See here.
  629benchmark(Ps, Index, DocType, Body, Reply) :-
  630    benchmark(Ps, Index, DocType, _{}, Body, Reply).
  631
  632benchmark(Ps, Index, DocType, Params, Body, Reply) :-
  633    make_context([Index, DocType, '_bench'], Context),
  634    perform_request(Ps, put, Context, Params, Body, _, Reply).
 abort_benchmark(+Ps, +Name, -Reply) is semidet
 abort_benchmark(+Ps, +Name, +Params, -Reply) is semidet
Aborts a running benchmark. See here.
  642abort_benchmark(Ps, Name, Reply) :-
  643    abort_benchmark(Ps, Name, _{}, Reply).
  644
  645abort_benchmark(Ps, Name, Params, Reply) :-
  646    make_context(['_bench', abort, Name], Context),
  647    perform_request(Ps, post, Context, Params, _, _, Reply).
 list_benchmark(+Ps, +Index, +DocType, -Reply) is semidet
 list_benchmark(+Ps, +Index, +DocType, +Params, -Reply) is semidet
View the progress of long-running benchmarks. See here.
  655list_benchmark(Ps, Index, DocType, Reply) :-
  656    list_benchmark(Ps, Index, DocType, _{}, Reply).
  657
  658list_benchmark(Ps, Index, DocType, Params, Reply) :-
  659    make_context([Index, DocType, '_bench'], Context),
  660    perform_request(Ps, get, Context, Params, _, Reply).
 put_script(+Ps, +Lang, +ID, +Body, -Reply) is semidet
 put_script(+Ps, +Lang, +ID, +Params, +Body, -Reply) is semidet
Create a script in given language with specified ID. See here.
  668put_script(Ps, Lang, ID, Body, Reply) :-
  669    put_script(Ps, Lang, ID, _{}, Body, Reply).
  670
  671put_script(Ps, Lang, ID, Params, Body, Reply) :-
  672    forall(member(Value-Name, [Lang-lang, ID-id, Body-body]), non_empty(Value, Name)),
  673    make_context(['_scripts', Lang, ID], Context),
  674    perform_request(Ps, put, Context, Params, Body, _, Reply).
 get_script(+Ps, +Lang, +ID, -Reply) is semidet
 get_script(+Ps, +Lang, +ID, +Params, -Reply) is semidet
Retrieve a script from the API. See here.
  682get_script(Ps, Lang, ID, Reply) :-
  683    get_script(Ps, Lang, ID, _{}, Reply).
  684
  685get_script(Ps, Lang, ID, Params, Reply) :-
  686    forall(member(Value-Name, [Lang-lang, ID-id]), non_empty(Value, Name)),
  687    make_context(['_scripts', Lang, ID], Context),
  688    perform_request(Ps, get, Context, Params, _, Reply).
 delete_script(+Ps, +Lang, +ID, -Reply) is semidet
 delete_script(+Ps, +Lang, +ID, +Params, -Reply) is semidet
Remove a stored script from elasticsearch. See here.
  696delete_script(Ps, Lang, ID, Reply) :-
  697    delete_script(Ps, Lang, ID, _{}, Reply).
  698
  699delete_script(Ps, Lang, ID, Params, Reply) :-
  700    forall(member(Value-Name, [Lang-lang, ID-id]), non_empty(Value, Name)),
  701    make_context(['_scripts', Lang, ID], Context),
  702    perform_request(Ps, delete, Context, Params, _, Reply).
 put_template(+Ps, +ID, +Body, -Reply) is semidet
 put_template(+Ps, +ID, +Params, +Body, -Reply) is semidet
Create a search template. See here.
  710put_template(Ps, ID, Body, Reply) :-
  711    put_template(Ps, ID, _{}, Body, Reply).
  712
  713put_template(Ps, ID, Params, Body, Reply) :-
  714    forall(member(Value-Name, [ID-id, Body-body]), non_empty(Value, Name)),
  715    make_context(['_search', template, ID], Context),
  716    perform_request(Ps, put, Context, Params, Body, _, Reply).
 get_template(+Ps, +ID, -Reply) is semidet
 get_template(+Ps, +ID, +Params, -Reply) is semidet
Retrieve a search template. See here.
  724get_template(Ps, ID, Reply) :-
  725    get_template(Ps, ID, _{}, Reply).
  726
  727get_template(Ps, ID, Params, Reply) :-
  728    non_empty(ID, id),
  729    make_context(['_search', template, ID], Context),
  730    perform_request(Ps, get, Context, Params, _, Reply).
 delete_template(+Ps, +ID, -Reply) is semidet
 delete_template(+Ps, +ID, +Params, -Reply) is semidet
Delete a search template. See here.
  738delete_template(Ps, ID, Reply) :-
  739    delete_template(Ps, ID, _{}, Reply).
  740
  741delete_template(Ps, ID, Params, Reply) :-
  742    make_context(['_search', template, ID], Context),
  743    perform_request(Ps, delete, Context, Params, _, Reply).
 search_exists(+Ps, +Index, +DocType, +Body, -Reply) is semidet
 search_exists(+Ps, +Index, +DocType, +Params, +Body, -Reply) is semidet
The exists API allows to easily determine if any matching documents exist for a provided query. See here.
  752search_exists(Ps, Index, DocType, Body, Reply) :-
  753    search_exists(Ps, Index, DocType, _{}, Body, Reply).
  754
  755search_exists(Ps, Index, DocType, Params, Body, Reply) :-
  756    make_context([Index, DocType, '_search', exists], Context),
  757    perform_request(Ps, get, Context, Params, Body, _, Reply).
  758
  759bulk_body(Body, BulkBody) :-
  760    atom(Body), !,
  761    (   sub_atom(Body, _, 1, 0, '\n')
  762    ->  BulkBody = Body
  763    ;   atomic_concat(Body, '\n', BulkBody)
  764    ).
  765
  766bulk_body(Body, BulkBody) :-
  767    is_dict(Body), !,
  768    atom_json_dict(BulkBody, Body, [as(atom)]).
  769
  770bulk_body([], '') :- !.
  771bulk_body([H|T], BulkBody) :- !,
  772    bulk_body(T, BulkBody0),
  773    bulk_body(H, BulkBody1),
  774    atomic_list_concat([BulkBody1, BulkBody0], '\n', BulkBody)