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.
-
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.
-
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
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
…) althoughXContentBuilder
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.
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.