Example usage for org.springframework.data.elasticsearch.annotations FieldType Date

List of usage examples for org.springframework.data.elasticsearch.annotations FieldType Date

Introduction

In this page you can find the example usage for org.springframework.data.elasticsearch.annotations FieldType Date.

Prototype

FieldType Date

To view the source code for org.springframework.data.elasticsearch.annotations FieldType Date.

Click Source Link

Usage

From source file:com.github.vanroy.springdata.jest.MappingBuilder.java

/**
 * Apply mapping for a single @Field annotation
 *
 * @throws IOException// www  .  j  a v a2  s. co m
 */
private static void addSingleFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field,
        Field fieldAnnotation, boolean nestedOrObjectField) throws IOException {
    xContentBuilder.startObject(field.getName());
    if (!nestedOrObjectField) {
        xContentBuilder.field(FIELD_STORE, fieldAnnotation.store());
    }
    if (FieldType.Auto != fieldAnnotation.type()) {
        xContentBuilder.field(FIELD_TYPE, fieldAnnotation.type().name().toLowerCase());
        if (FieldType.Date == fieldAnnotation.type() && DateFormat.none != fieldAnnotation.format()) {
            xContentBuilder.field(FIELD_FORMAT,
                    DateFormat.custom == fieldAnnotation.format() ? fieldAnnotation.pattern()
                            : fieldAnnotation.format());
        }
    }
    if (FieldIndex.not_analyzed == fieldAnnotation.index() || FieldIndex.no == fieldAnnotation.index()) {
        xContentBuilder.field(FIELD_INDEX, fieldAnnotation.index().name().toLowerCase());
    }
    if (isNotBlank(fieldAnnotation.searchAnalyzer())) {
        xContentBuilder.field(FIELD_SEARCH_ANALYZER, fieldAnnotation.searchAnalyzer());
    }
    if (isNotBlank(fieldAnnotation.analyzer())) {
        xContentBuilder.field(FIELD_INDEX_ANALYZER, fieldAnnotation.analyzer());
    }
    xContentBuilder.endObject();
}