picturesafe-search supports a FieldConfiguration to define the mapping for an Elasticsearch index.
Field configurations are necessary to determine the data type and other properties of an index field.
If no FieldConfiguration is defined, Elasticsearch creates the mapping based on the data stored in the index.
For simple use cases (e.g. if there is no need for a fulltext search or only simple data types will be used), an empty FieldConfiguration list can be returned:
Spring configuration
The following example defines three fields for the Elasticsearch index:
Field ‘id’ (Elasticsearch type text, sortable)
Field ‘fulltext’ (Elasticsearch type text)
Field ‘title’ (Elasticsearch type text, within fulltext, aggregatable, sortable)
Spring configuration
The above field definition results in the following Elasticsearch mapping:
Field properties
Field data types
The simplest case is to define only the data type of the index field via a field configuration:
The following predefined Elasticsearch field data types are supported:
Elasticsearch type
TEXT
LONG
INTEGER
SHORT
BYTE
DOUBLE
FLOAT
DATE
BOOLEAN
NESTED
COMPLETION
Other field data types supported by Elasticsearch can be passed as string, for example:
System field configurations
The following system field configurations exist to give other fields additional functionality, e.g. for full text search.
System field: ID
The system field configuration FieldConfiguration.ID_FIELD is required if documents with a (unique) ID are to be added to the Elasticsearch index, for example:
If no FieldConfiguration.ID_FIELD is defined, the documents can be added to the index without an ID:
System field: FULLTEXT_FIELD
If a fulltext search over several index fields is needed, the system field FieldConfiguration.FULLTEXT_FIELD must be defined.
In the following example, two more fields are defined in addition to the fulltext field, whose contents are to be found using the fulltext search:
With this configuration, a simple fulltext search using the fields title and caption can be performed as follows:
System field: SUGGEST_FIELD
If a suggest (‘search-as-you-type’) feature is to be implemented, the system field FieldConfiguration.SUGGEST_FIELD must be defined.
The following example defines ‘suggest’ support for the field city:
With this configuration, a suggest query for a maximum of ten suggestions can be performed as follows:
Additional field properties
Field property: sortable
Fields can be defined as sortable:
In this case they can be used as SortOption:
Field property: aggregatable
Fields can be defined as aggregatable:
In this case they can be returned as facets in the search result: