marcoscarceles / elasticsearch-lite

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Elasticsearch Lite plugin

An Elasticsearch plugin for Grails; This project is based on the great work done at https://github.com/noamt/elasticsearch-grails-plugin. Nonetheless this plugin takes a less opinionated, more pluggable, approach and it is just a thin layer on top of the ElasticSearch client.

Why would you want to fork the original Elasticsearch plugin?

  • The original plugin relies on a bespoke mapping closure, hard to extenda and maintain.

    • In contrast this plugin allows to define your own searchable classes and reusable mappings directly on Elasticsearch terms, using Groovy JsonBuilder

  • The original plugin hooked into the GORM datastore implementation.

    • Instead this plugin listens to Reactor GORM events.

Why not just use the plain Elasticsearch client?

This plugin still maps Elasticsearch indices and types to Gorm instances * It creates the indices and types on boot * It manages mapping conflicts and versions indices to resolve them * It listens to Reactor events to automatically index, update and delete domain objects * It simplifies the instantiation of an Elasticsearch client and exposes it via a service

How can I migrate?

This plugin relies on two annotations to mark domain classes as searchable and to map and marshall them to Elasticsearch documents: @Searchable and @Mapping.

@Mapping specifies that the domain class can be marshalled into an Elasticsearch document. It takes an ElasticSearchMarshaller subclass as value. ElasticSearchMarshaller defines the following two methods:

  • JsonBuilder getMapping() : Must return a JSON representation of the mapping for this type

  • toSource(T instance) : Must return any object that can be used as a source in the Elasticsearch java API (String, Map, ByteRef, XContentBuilder …​) although XContentBuilder is encouraged in order to compose multiple Marshallers.

@Searchable specifies that the domain class can be indexed and searched as document of type type on the Elasticsearch index index. All @Searchable annotated classes must be annotated with @Mapping as well.

To migrate from the elasticsearch-grails-plugin, replace the searchable closure with these two annotations. To do so, it is encouraged to copy your mappings JSON from an existing environment into your ElasticSearchMarshaller class.

This plugin does not include as many helper and dynamic methods as the original plugin and encourages users to use the plain Elasticsearch java API. These must be deleted. For extra help: * The client is accessible via elasticSearchService.client. * Request Builders are accesible via elasticSearchService.prepare…​ methods. * Marshallers are accesible via elasticSearchLiteContext. The plugin still eases the administration of Elasticsearch indices via the elasticSearchAdminService via helper methods and exposing an adminClient instance.

Versioning

The plugin is still in version 0.1.0-SNAPSHOT, which works with Grails 3.1.x and Elasticsearch 2.4.4. Part of the scope of this new plugin is to simplify versioning and make it easier to upgrade.

License

Copyright 2014 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

License:Other


Languages

Language:Groovy 99.7%Language:Shell 0.3%