Add keyword type to index type system

Elasticsearch 5.0 introduced different ways to search strings: [1],
either search whole values that we often refer to as keyword search,
or individual tokens, that we usually refer to as full-text search.

To reflect this change and support such fields in gerrit with ES 5 and
higher, add keyword type to gerrit index type system.

[1] https://www.elastic.co/blog/strings-are-dead-long-live-strings
Change-Id: I25bd157cd638695f5a3b533463008fcf7da9ac8d
This commit is contained in:
David Ostrovsky
2018-06-03 23:21:21 +02:00
committed by David Pursehouse
parent 90db6de2e0
commit 506125e71a
3 changed files with 8 additions and 1 deletions

View File

@@ -337,7 +337,7 @@ public abstract class AbstractLuceneIndex<K, V> implements Index<K, V> {
for (Object value : values.getValues()) {
doc.add(new LongField(name, ((Timestamp) value).getTime(), store));
}
} else if (type == FieldType.EXACT || type == FieldType.PREFIX) {
} else if (type == FieldType.KEYWORD || type == FieldType.EXACT || type == FieldType.PREFIX) {
for (Object value : values.getValues()) {
doc.add(new StringField(name, (String) value, store));
}

View File

@@ -39,6 +39,10 @@ public final class FieldDef<I, T> {
return new FieldDef.Builder<>(FieldType.EXACT, name);
}
public static FieldDef.Builder<String> keyword(String name) {
return new FieldDef.Builder<>(FieldType.KEYWORD, name);
}
public static FieldDef.Builder<String> fullText(String name) {
return new FieldDef.Builder<>(FieldType.FULL_TEXT, name);
}

View File

@@ -33,6 +33,9 @@ public class FieldType<T> {
/** A string field searched using exact-match semantics. */
public static final FieldType<String> EXACT = new FieldType<>("EXACT");
/** A Keyword field searched using non-analyzed-match semantics. */
public static final FieldType<String> KEYWORD = new FieldType<>("KEYWORD");
/** A string field searched using prefix. */
public static final FieldType<String> PREFIX = new FieldType<>("PREFIX");