Extending Elasticsearch Writing plugins, fast and easy!
Alexander Reelsen @spinscale alex@elastic.co
Slide 2
Elasticsearch in 10 seconds Search Engine (FTS, Analytics, Geo), real-time Distributed, scalable, highly available, resilient Interface: HTTP & JSON Centrepiece of the Elastic Stack (Kibana, Logstash, Beats, APM, ML, App/Site/Enterprise Search) Uneducated guess: Tens of thousands of clusters worldwide, hundreds of thousands of instances
Slide 3
Agenda Overview Building Testing Releasing Extension points
Slide 4
Overview Requirements, gotchas and some details
Slide 5
Overview Plugins are zip files own jars/dependencies loaded with its own classloader own security permissions
Slide 6
Security Manager? Permissions? But why?! Sandbox your java application Prevent certain calls by your application Policy file grants permissions FilePermission (read, write) SocketPermission (connect, listen, accept) URLPermission, PropertyPermission, …
Slide 7
Security Manager? Permissions? But why?! Each plugin needs to be packaged with a policy that grants certain operations
Slide 8
Building gradle clean assemble
Slide 9
Overview A plugin needs to be released for an Elasticsearch patch release Use the gradle plugin! Batteries included, lots of them Integration tests, license checks, checkstyle, notice files
Slide 10
Testing gradle clean check
Slide 11
Overview Unit tests: ESTestCase Integration tests: YAML Download ES, install plugin, start ES, run tests against HTTP
Slide 12
ESTestCase Randomized testing Logger Thread leak detector Deprecation warnings detection Test method names have to begin with void test…() assertBusy/awaitBusy
Slide 13
Extension points class MyPlugin extends Plugin
Slide 14
Overview ActionPlugin: Implement own actions, REST endpoints AnalysisPlugin: Add custom parts to analysis chain ClusterPlugin: Implement own shard allocation logic DiscoveryPlugin: Add (often API based) host discovery IngestPlugin: Custom ingest processors MapperPlugin: Custom mapping data types NetworkPlugin: Network implementations (i.e. netty replacement) RepositoryPlugin: Snapshot/restore repository implementations ScriptPlugin: Script Engines, Script Contexts SearchPlugin: Queries, Highlighter, Suggester, Aggregations, Rescoring, Search Extensions ReloadablePlugin: Ensure a plugin can reload its state
Slide 15
Overview main class: org.elasticsearch.plugins.Plugin settings registration & filter custom cluster state metadata cluster state listener index modules (search listener, index event listener)
Overview PluginService check for modules & plugins directory check jar hell check version create classloader reload lucene SPI load Plugin class instantiate Plugin class
Ingest lang-detect processor PUT /my-index/my-type/1?pipeline=langdetect-pipeline { “my_field” : “This is hopefully an english text, that will be detected.” } GET /my-index/my-type/1 { “my_field” : “This is hopefully an english text, that will be detected.”, “language”: “en” }
Slide 21
Custom query parser Ecommerce use-case clean data non expert searches