#881 - Split DocPropertyType.STRING into KEYWORD and TEXT ... for ElasticSearch 5.x support

This commit is contained in:
Rob Bygrave
2016-11-17 22:59:50 +13:00
parent 0322b37ae7
commit b0dae02c42
13 changed files with 30 additions and 22 deletions
@@ -1388,20 +1388,15 @@ public class BeanProperty implements ElPropertyValue, Property {
if (mapping.includesProperty(prefix, name)) {
DocPropertyType type = scalarType.getDocType();
DocPropertyOptions options = docOptions.copy();
if (DocPropertyType.UUID == type || DocPropertyType.ENUM == type || isStringId(type)) {
options.setCode(true);
if (isKeywordType(type, docOptions)) {
type = DocPropertyType.KEYWORD;
}
mapping.add(new DocPropertyMapping(name, type, options));
mapping.add(new DocPropertyMapping(name, type, docOptions));
}
}
/**
* Return true if this is a String Id property and should be treated as a code by the document store.
*/
private boolean isStringId(DocPropertyType type) {
return DocPropertyType.STRING == type && (id || discriminator);
private boolean isKeywordType(DocPropertyType type, DocPropertyOptions docOptions) {
return type == DocPropertyType.TEXT && (docOptions.isCode() || id || discriminator);
}
public void merge(EntityBean bean, EntityBean existing) {
@@ -25,7 +25,7 @@ public class ScalarTypeArrayList extends ScalarTypeJsonCollection<List> {
private static ScalarTypeArrayList LONG = new ScalarTypeArrayList("bigint", DocPropertyType.LONG, ArrayElementConverter.LONG);
private static ScalarTypeArrayList INTEGER = new ScalarTypeArrayList("integer", DocPropertyType.INTEGER, ArrayElementConverter.INTEGER);
private static ScalarTypeArrayList DOUBLE = new ScalarTypeArrayList("float", DocPropertyType.DOUBLE, ArrayElementConverter.DOUBLE);
private static ScalarTypeArrayList STRING = new ScalarTypeArrayList("varchar", DocPropertyType.STRING, ArrayElementConverter.STRING);
private static ScalarTypeArrayList STRING = new ScalarTypeArrayList("varchar", DocPropertyType.TEXT, ArrayElementConverter.STRING);
static PlatformArrayTypeFactory factory() {
return new Factory();
@@ -16,7 +16,7 @@ class ScalarTypeArrayListH2 extends ScalarTypeArrayList {
private static ScalarTypeArrayListH2 LONG = new ScalarTypeArrayListH2("bigint", DocPropertyType.LONG, ArrayElementConverter.LONG);
private static ScalarTypeArrayListH2 INTEGER = new ScalarTypeArrayListH2("integer", DocPropertyType.INTEGER, ArrayElementConverter.INTEGER);
private static ScalarTypeArrayListH2 DOUBLE = new ScalarTypeArrayListH2("double", DocPropertyType.DOUBLE, ArrayElementConverter.DOUBLE);
private static ScalarTypeArrayListH2 STRING = new ScalarTypeArrayListH2("varchar", DocPropertyType.STRING, ArrayElementConverter.STRING);
private static ScalarTypeArrayListH2 STRING = new ScalarTypeArrayListH2("varchar", DocPropertyType.TEXT, ArrayElementConverter.STRING);
static PlatformArrayTypeFactory factory() {
return new ScalarTypeArrayListH2.Factory();
@@ -129,7 +129,7 @@ public abstract class ScalarTypeBaseVarchar<T> extends ScalarTypeBase<T> {
@Override
public DocPropertyType getDocType() {
return DocPropertyType.STRING;
return DocPropertyType.TEXT;
}
}
@@ -112,7 +112,7 @@ public class ScalarTypeDuration extends ScalarTypeBase<Duration> {
@Override
public DocPropertyType getDocType() {
return DocPropertyType.STRING;
return DocPropertyType.KEYWORD;
}
}
@@ -119,6 +119,6 @@ public class ScalarTypeJodaLocalTime extends ScalarTypeBase<LocalTime> {
@Override
public DocPropertyType getDocType() {
return DocPropertyType.STRING;
return DocPropertyType.KEYWORD;
}
}
@@ -105,7 +105,7 @@ public class ScalarTypeLocalTime extends ScalarTypeBase<LocalTime> {
@Override
public DocPropertyType getDocType() {
return DocPropertyType.STRING;
return DocPropertyType.KEYWORD;
}
}
@@ -129,7 +129,7 @@ public class ScalarTypeMonthDay extends ScalarTypeBase<MonthDay> {
@Override
public DocPropertyType getDocType() {
return DocPropertyType.STRING;
return DocPropertyType.KEYWORD;
}
}
@@ -96,6 +96,6 @@ public class ScalarTypeString extends ScalarTypeBase<String> {
@Override
public DocPropertyType getDocType() {
return DocPropertyType.STRING;
return DocPropertyType.TEXT;
}
}
@@ -98,7 +98,7 @@ public class ScalarTypeTime extends ScalarTypeBase<Time> {
@Override
public DocPropertyType getDocType() {
return DocPropertyType.STRING;
return DocPropertyType.KEYWORD;
}
}
@@ -130,7 +130,7 @@ public class DocMappingBuilder {
public void visitProperty(DocPropertyMapping property) {
DocPropertyOptions options = property.getOptions();
if (options != null && Boolean.TRUE.equals(options.getSortable())) {
if (options != null && options.isSortable()) {
String fullPath = pathStack.peekFullPath(property.getName());
sortableMap.put(fullPath, fullPath + ".raw");
}
@@ -80,6 +80,10 @@ public class DocPropertyOptions {
return sb.toString();
}
public boolean isCode() {
return Boolean.TRUE.equals(code);
}
public Boolean getCode() {
return code;
}
@@ -88,6 +92,10 @@ public class DocPropertyOptions {
this.code = code;
}
public boolean isSortable() {
return Boolean.TRUE.equals(sortable);
}
public Boolean getSortable() {
return sortable;
}
@@ -16,9 +16,14 @@ public enum DocPropertyType {
UUID,
/**
* String.
* Keyword/code string content not expected to be analysed.
*/
STRING,
KEYWORD,
/**
* String content expected to be analysed.
*/
TEXT,
/**
* Boolean.