ElasticConfig Mapping Annotations

ElasticConfig Mapping Annotations is a Java project which allows you to automatically configure the analysis and mapping of an ElasticSearch index based on annotations

License

License

Categories

Categories

Search Business Logic Libraries Elasticsearch
GroupId

GroupId

be.intersentia.elasticsearch
ArtifactId

ArtifactId

mapping_annotations
Last Version

Last Version

0.7.8
Release Date

Release Date

Type

Type

jar
Description

Description

ElasticConfig Mapping Annotations
ElasticConfig Mapping Annotations is a Java project which allows you to automatically configure the analysis and mapping of an ElasticSearch index based on annotations
Project URL

Project URL

https://github.com/intersentia/elasticconfig
Source Code Management

Source Code Management

https://github.com/intersentia/elasticconfig

Download mapping_annotations

How to add to project

<!-- https://jarcasting.com/artifacts/be.intersentia.elasticsearch/mapping_annotations/ -->
<dependency>
    <groupId>be.intersentia.elasticsearch</groupId>
    <artifactId>mapping_annotations</artifactId>
    <version>0.7.8</version>
</dependency>
// https://jarcasting.com/artifacts/be.intersentia.elasticsearch/mapping_annotations/
implementation 'be.intersentia.elasticsearch:mapping_annotations:0.7.8'
// https://jarcasting.com/artifacts/be.intersentia.elasticsearch/mapping_annotations/
implementation ("be.intersentia.elasticsearch:mapping_annotations:0.7.8")
'be.intersentia.elasticsearch:mapping_annotations:jar:0.7.8'
<dependency org="be.intersentia.elasticsearch" name="mapping_annotations" rev="0.7.8">
  <artifact name="mapping_annotations" type="jar" />
</dependency>
@Grapes(
@Grab(group='be.intersentia.elasticsearch', module='mapping_annotations', version='0.7.8')
)
libraryDependencies += "be.intersentia.elasticsearch" % "mapping_annotations" % "0.7.8"
[be.intersentia.elasticsearch/mapping_annotations "0.7.8"]

Dependencies

compile (5)

Group / Artifact Type Version
org.apache.commons : commons-collections4 jar 4.1
org.apache.commons : commons-lang3 jar 3.5
io.github.classgraph : classgraph jar 4.8.43
io.github.lukehutch : fast-classpath-scanner jar 3.1.13
org.apache.logging.log4j : log4j-api jar 2.13.2

test (4)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-api jar 5.0.0-M4
org.hamcrest : hamcrest-all jar 1.1
org.mockito : mockito-all jar 1.8.5
org.apache.logging.log4j : log4j-core jar 2.13.2

Project Modules

There are no modules declared in this project.

elasticconfig

Introduction

ElasticConfig Mapping Annotations is a Java project which allows you to automatically configure the analysis and mapping of an ElasticSearch index based on annotations.

Usage

First create an annotated POJO representing your ElasticSearch type:

@Filter(name = "delimiter_catenate", type = Filter.WORD_DELIMITER, properties = {
		@Property(key = "catenate_words", value = "true"),
		@Property(key = "catenate_numbers", value = "true")
})
@CustomAnalyzer(name = "default", tokenizer = Tokenizer.WHITESPACE, filters = {
		Filter.LOWERCASE, "delimiter_catenate", Filter.ASCII_FOLDING, Filter.PORTER_STEM
})
@CustomAnalyzer(name = "reference", tokenizer = Tokenizer.WHITESPACE, filters = {
		Filter.ASCII_FOLDING, Filter.LOWERCASE
})
@TextMapping(field = "search_field", index = true, store = false)
public class LibraryItem implements Serializable {
    public static final String NAME = "LibraryItem";

    @KeywordMapping(index = true, store = true)
    private String publicationId;
    @KeywordMapping(index = true, store = true, copyTo = "search_field")
    private String name;
    @TextMapping(index = false, store = true, analyzer = "reference")
    private String code;
    @TextMapping(index = false, store = false, copyTo = "search_field")
    private String description;

    // getters and setters
}

Then, use the AnalysisFactory and MappingFactory to complete your CreateIndexRequest:

class Example {
    public static void main(String[] args) {
        CreateIndexRequest request = new CreateIndexRequest("library");
        request.settings(AnalysisFactory.createAnalysis(Collections.singletonList(LibraryItem.class)));
        request.mapping(LibraryItem.NAME, MappingFactory.createMapping(Collections.singletonList(LibraryItem.class), true));
		CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT);
		if (!response.isAcknowledged) {
			throw new IllegalStateException("Index could not be created");
		}
    }
}

Alternatively, you can ask ElasticConfig to automatically create indices for all types in a certain package which are annotated with @Index:

class Example {
    public static void main(String[] args) {
        ConfigurationScanner.scan("be.intersentia.elasticsearch").configure();
    }
}
be.intersentia.elasticsearch

intersentia

Versions

Version
0.7.8
0.7.7
0.7.6
0.7.5
0.7.4
0.7.3
0.7.2
0.7.0
0.6.2
0.6.1
0.6.0