scripting.asciidoc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. [[breaking_50_scripting]]
  2. === Script related changes
  3. ==== Indexed scripts and templates
  4. Indexed scrips and templates have been replaced by <<modules-scripting-stored-scripts,stored scripts>>
  5. which stores the scripts and templates in the cluster state instead of a dedicate `.scripts` index.
  6. For the size of stored scripts there is a soft limit of 65535 bytes. If scripts exceed that size then
  7. the `script.max_size_in_bytes` setting can be added to elasticsearch.yml to change the soft limit to a higher value.
  8. If scripts are really large, other options like native scripts should be considered.
  9. Previously indexed scripts in the `.scripts` index will not be used any more as
  10. Elasticsearch will now try to fetch the scripts from the cluster state. Upon upgrading
  11. to 5.x the `.scripts` index will remain to exist, so it can be used by a script to migrate
  12. the stored scripts from the `.scripts` index into the cluster state. The format of the scripts
  13. hasn't changed.
  14. ===== Python migration script
  15. The following Python script can be used to import your indexed scripts into the cluster state
  16. as stored scripts:
  17. [source,python]
  18. -----------------------------------
  19. from elasticsearch import Elasticsearch,helpers
  20. es = Elasticsearch([
  21. {'host': 'localhost'}
  22. ])
  23. for doc in helpers.scan(es, index=".scripts", preserve_order=True):
  24. es.put_script(lang=doc['_type'], id=doc['_id'], body=doc['_source'])
  25. -----------------------------------
  26. This script makes use of the official Elasticsearch Python client and
  27. therefore you need to make sure that your have installed the client in your
  28. environment. For more information on this please see
  29. https://www.elastic.co/guide/en/elasticsearch/client/python-api/current/index.html[`elasticsearch-py`].
  30. ===== Perl migration script
  31. The following Perl script can be used to import your indexed scripts into the cluster state
  32. as stored scripts:
  33. [source,perl]
  34. -----------------------------------
  35. use Search::Elasticsearch;
  36. my $es = Search::Elasticsearch->new( nodes => 'localhost:9200');
  37. my $scroll = $es->scroll_helper( index => '.scripts', sort => '_doc');
  38. while (my $doc = $scroll->next) {
  39. $e->put_script(
  40. lang => $doc->{_type},
  41. id => $doc->{_id},
  42. body => $doc->{_source}
  43. );
  44. }
  45. -----------------------------------
  46. This script makes use of the official Elasticsearch Perl client and
  47. therefore you need to make sure that your have installed the client in your
  48. environment. For more information on this please see
  49. https://metacpan.org/pod/Search::Elasticsearch[`Search::Elasticsearch`].
  50. ===== Verifying script migration
  51. After you have moved the scripts via the provided script or otherwise then you can verify with the following
  52. request if the migration has happened successfully:
  53. [source,js]
  54. -----------------------------------
  55. GET _cluster/state?filter_path=metadata.stored_scripts
  56. -----------------------------------
  57. The response should include all your scripts from the `.scripts` index.
  58. After you have verified that all your scripts have been moved, optionally as a last step,
  59. you can delete the `.scripts` index as Elasticsearch no longer uses it.
  60. ==== Indexed scripts Java APIs
  61. All the methods related to interacting with indexed scripts have been removed.
  62. The Java API methods for interacting with stored scripts have been added under `ClusterAdminClient` class.
  63. The sugar methods that used to exist on the indexed scripts API methods don't exist on the methods for
  64. stored scripts. The only way to provide scripts is by using `BytesReference` implementation, if a string needs to be
  65. provided the `BytesArray` class should be used.