Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@
boolean source() default true;

boolean all() default true;

boolean ttl() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ private void parseClassMapping(Class<?> clazz, String pathPrefix) throws Introsp
classDefinitionMap.put("_source", MapUtil.getMap("enabled", esObject.source()));
classDefinitionMap.put("_type", MapUtil.getMap(new String[] { "store", "index" }, new Object[] { esObject.store(), esObject.index() }));

if(esObject.ttl()) {
classDefinitionMap.put("_ttl", MapUtil.getMap("enabled", true));
}

this.fieldsMappingBuilder.parseFieldMappings(clazz, classDefinitionMap, facetFields, filteredFields, fetchContexts, pathPrefix);

ObjectMapper mapper = new ObjectMapper();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import junit.framework.Assert;

import org.elasticsearch.mapping.model.City;
import org.elasticsearch.mapping.model.Person;
import org.junit.Test;

Expand All @@ -28,4 +29,17 @@ public void testSimpleClassMapping() throws IntrospectionException, JsonGenerati
"{\"person\":{\"_type\":{\"index\":\"not_analyzed\",\"store\":false},\"_id\":{\"index\":\"no\",\"store\":false,\"path\":\"id\"},\"_source\":{\"enabled\":true},\"properties\":{\"address\":{\"properties\":{\"city\":{\"include_in_all\":false,\"index\":\"not_analyzed\",\"store\":false,\"boost\":1.0,\"term_vector\":\"no\",\"type\":\"string\"}},\"type\":\"nested\"},\"lastname\":{\"include_in_all\":true,\"index\":\"analyzed\",\"store\":false,\"boost\":1.0,\"term_vector\":\"no\",\"type\":\"string\"},\"firstname\":{\"include_in_all\":false,\"index\":\"no\",\"store\":false,\"boost\":1.0,\"term_vector\":\"no\",\"type\":\"string\"}},\"_all\":{\"enabled\":true}}}",
personMapping);
}

@Test
public void ttlTest() throws IntrospectionException, JsonGenerationException, JsonMappingException,
IOException {
MappingBuilder mappingBuilder = new MappingBuilder();
mappingBuilder.initialize("org.elasticsearch.mapping.model");
String personMapping = mappingBuilder.getMapping(City.class);
Assert.assertEquals(
"{\"city\":{\"_type\":{\"index\":\"not_analyzed\",\"store\":false},\"_id\":{\"index\":\"no\",\"store\":false,\"path\":\"id\"},\"_source\":{\"enabled\":true},\"_ttl\":{\"enabled\":true},\"properties\":{},\"_all\":{\"enabled\":true}}}",
personMapping);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.elasticsearch.mapping.model;

import org.elasticsearch.annotation.ESObject;
import org.elasticsearch.annotation.Id;

/**
*
* @author luc boutier
*/
@ESObject(ttl = true)
public class City {
@Id
private String id;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

}