How do you integrate ElasticSearch with Magnolia CMS?

0
2887

Magnolia Content App Elastic Search & S3 is an content app for Magnolia CMS permit to show items from source, create item, edit item simplify integration with multiple source enabling view in table of contents.

Magnolia CMS is a Content Management System written in Java that leads where editorial page composition is a core activity and has some functionality out-of-box as caching, user management, creating a page with the template, defining a template, creating an app that assolve to a specific scope, have build-in filesystem (like JCR) and permit to configure only YAML based a long plethora of functionality.

Elastic Search is a content engine standard de facto for large applications used to the flexibility and speeds up every search including autocomplete and highlight functionality.

Content App for Elastic Search

Magnolia CMS support creating apps for a specific scope and simplifying some task.

See the video below here a quickly through using the Content App:

The app permits you to connect (now, in the future I expand the source connectable) to :
  • an elastic search instance shows/edit/add documents in the table from the index you prefer. You can search items with the Elastic Search engine directly in the specific tab. You have not only in Magnolia out-the-box without Kibana a tool for searching, adding, editing, delete an item on a specific index, but you have a framework for developers to map index, and fields to one DTO and facilitate import/export, and conversion from elastic search data to another connectable source).
  • An S3 bucket shows all files present, download/upload directly, and so on the same facilities to import/export/conversion from the connectable source. This last feature it’s only for developers, but another will be added for managing conversion data, import, and export.
  • It’s a generic connector for a source, simplifying the process to connect another source. It’s necessary to write 3 classes for enabling another source and have added/edit/showing items. (See this article)

In the chapters after we discuss more deeply in features and how to customize the app.

If you want to learn more about how it’s possible here I talk with more details.

Also you are a developer and you want to contribute to the project where there is a source code (on Magnolia Community – ex Forge) there are some pull requests you can develop.

Contact me as maintainer I give you all information for getting started on this projects.

Basically in the Content App you could do this actions:

Actions could be done in Content App Elastic Search
Actions could be done in Content App Elastic Search

For “choose source” we discuss about choose what source you want to connect, within Elastic Search or S3, in this phase you must insert all informations require to connect to one instance.

For example ElasticSearch you need ip server instance and port, for S3 you need accessToken, Secret Key and region.

For “choose Class represent item” it depends to source you have been choosed, and could be necessary ensure you have one class correctly represent the fields of document you want to search/add or edit.

Connect to elastic search instance

How generic content app for more sources, you must select one source you want to connect.

At the moment the app manages two sources: Elastic Search and S3.

In this article we concentrate on Elastic Search, so insert the address and port for identifying one instance and click “Connect”.

it initializes a connection with Elastic Search instance for be ready to make a search with a specific index.

For now, I test with Elastic Search 7.17 and I plan to extends supports with security Elastic Search and maintain support with major version Elastic Search.

Edit data in elastic Search instance

Content app permits to showing all documents of one index Elastic Search. When you select  on combobox the index (that define the index name how it’s saved on instance), in table there show all documents using Elastic Search library released.

Search data in elastic Search instance

You can search text in all documents which index you have selected using the functionality Elastic Search implemented.

All documents founds will be shown in the table on the right side of the app.

We could ask where we define columns and how we define the index can be shown.

It’s defined by one class DTO which extends a particular class and has one annotation that describes the index name, which field is id.

In this article, we describe how we can extend management to another index and contribute for implement new source management.

How do you install Content App Elastic Search and S3?

To use that app, add a dependency in your pom.xml:

<code>
  <dependency>
    <groupId>net.seniorsoftwareengineer</groupId>
    <artifactId>magnolia-cms-content-app-elasticsearch</artifactId>
    <version>1.1</version>
  </dependency>
</code>

Add in your pom.xml the link to repository

<distributionManagement>
   <repository>
     <id>github</id>
     <name>GitHub OWNER Apache Maven Packages</name>
     <url>https://maven.pkg.github.com/AndreaPagliacci/magnolia-cms-content-app-elasticsearch-s3</url>
   </repository>
</distributionManagement>
Build your solution with:
mvn install

Requirements for have best experience from Content App

You must create your DTO class represent the fields you want to add,edit, search which contains all fields and have the signature of index name will be linked.

@GenericEntity(name = "test", fieldId = "id")
public class Log extends GenericItem {
	private String id;
	private String level;
	private String loggerName;
}

In this case we suppose you want to connect with index named “test” and have 3 fields and id it’s the key which ensure univocy id.

That’s class you must create in the module you have added the dependency of content app.

With reflections all class extends GenericItem and have annotation GenericEntity will be showed in the “Manage Item” sections.

Create custom document fields class that you have in your Elastic Search instance
Create custom document fields class that you have in your Elastic Search instance