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

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

Introduction

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

Prototype

FieldType Auto

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

Click Source Link

Usage

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

static XContentBuilder buildMapping(Class clazz, String indexType, String idFieldName, String parentType)
        throws IOException {

    XContentBuilder mapping = jsonBuilder().startObject().startObject(indexType);
    // Parent// w  w  w  .j av a2  s  . c o  m
    if (hasText(parentType)) {
        mapping.startObject(FIELD_PARENT).field(FIELD_TYPE, parentType).endObject();
    }

    // Properties
    XContentBuilder xContentBuilder = mapping.startObject(FIELD_PROPERTIES);

    mapEntity(xContentBuilder, clazz, true, idFieldName, EMPTY, false, FieldType.Auto, null);

    return xContentBuilder.endObject().endObject().endObject();
}

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

/**
 * Apply mapping for a single @Field annotation
 *
 * @throws IOException/*from   ww  w. j  a  v  a  2  s  . c  o  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();
}

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

/**
 * Apply mapping for a single nested @Field annotation
 *
 * @throws IOException//  w  ww.  j a v a  2  s.co m
 */
private static void addNestedFieldMapping(XContentBuilder builder, java.lang.reflect.Field field,
        InnerField annotation) throws IOException {
    builder.startObject(annotation.suffix());
    //builder.field(FIELD_STORE, annotation.store());
    if (FieldType.Auto != annotation.type()) {
        builder.field(FIELD_TYPE, annotation.type().name().toLowerCase());
    }
    if (FieldIndex.not_analyzed == annotation.index()) {
        builder.field(FIELD_INDEX, annotation.index().name().toLowerCase());
    }
    if (isNotBlank(annotation.searchAnalyzer())) {
        builder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
    }
    if (isNotBlank(annotation.indexAnalyzer())) {
        builder.field(FIELD_INDEX_ANALYZER, annotation.indexAnalyzer());
    }
    builder.endObject();
}

From source file:org.springframework.data.elasticsearch.core.MappingBuilder.java

/**
 * Apply mapping for a single @Field annotation
 *
 * @param xContentBuilder//from  w ww .  jav  a 2s.c  om
 * @param field
 * @param fieldAnnotation
 * @throws IOException
 */
private static void addSingleFieldMapping(XContentBuilder xContentBuilder, java.lang.reflect.Field field,
        Field fieldAnnotation) throws IOException {
    xContentBuilder.startObject(field.getName());
    xContentBuilder.field(FIELD_STORE, fieldAnnotation.store());
    if (FieldType.Auto != fieldAnnotation.type()) {
        xContentBuilder.field(FIELD_TYPE, fieldAnnotation.type().name().toLowerCase());
    }
    if (FieldIndex.not_analyzed == fieldAnnotation.index()) {
        xContentBuilder.field(FIELD_INDEX, fieldAnnotation.index().name().toLowerCase());
    }
    if (isNotBlank(fieldAnnotation.searchAnalyzer())) {
        xContentBuilder.field(FIELD_SEARCH_ANALYZER, fieldAnnotation.searchAnalyzer());
    }
    if (isNotBlank(fieldAnnotation.indexAnalyzer())) {
        xContentBuilder.field(FIELD_INDEX_ANALYZER, fieldAnnotation.indexAnalyzer());
    }
    xContentBuilder.endObject();
}

From source file:org.springframework.data.elasticsearch.core.MappingBuilder.java

/**
 * Apply mapping for a single nested @Field annotation
 *
 * @param builder//  www  .j  a v a  2  s. c  om
 * @param field
 * @param annotation
 * @throws IOException
 */
private static void addNestedFieldMapping(XContentBuilder builder, java.lang.reflect.Field field,
        NestedField annotation) throws IOException {
    builder.startObject(field.getName() + "." + annotation.dotSuffix());
    builder.field(FIELD_STORE, annotation.store());
    if (FieldType.Auto != annotation.type()) {
        builder.field(FIELD_TYPE, annotation.type().name().toLowerCase());
    }
    if (FieldIndex.not_analyzed == annotation.index()) {
        builder.field(FIELD_INDEX, annotation.index().name().toLowerCase());
    }
    if (isNotBlank(annotation.searchAnalyzer())) {
        builder.field(FIELD_SEARCH_ANALYZER, annotation.searchAnalyzer());
    }
    if (isNotBlank(annotation.indexAnalyzer())) {
        builder.field(FIELD_INDEX_ANALYZER, annotation.indexAnalyzer());
    }
    builder.endObject();
}