NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_COMPONENT.getType())
.requireProjectAuthorization();
- mapping.stringFieldBuilder(FIELD_PROJECT_UUID).build();
- mapping.stringFieldBuilder(FIELD_KEY).addSubFields(SORTABLE_ANALYZER).build();
- mapping.stringFieldBuilder(FIELD_NAME)
+ mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).build();
+ mapping.keywordFieldBuilder(FIELD_KEY).addSubFields(SORTABLE_ANALYZER).build();
+ mapping.keywordFieldBuilder(FIELD_NAME)
.termVectorWithPositionOffsets()
.addSubFields(NAME_ANALYZERS)
.build();
- mapping.stringFieldBuilder(FIELD_QUALIFIER).build();
+ mapping.keywordFieldBuilder(FIELD_QUALIFIER).build();
}
}
public static final String TYPE = "type";
public static final String INDEX = "index";
public static final String ANALYZED = "analyzed";
- public static final String STRING = "string";
+ public static final String FIELD_TYPE_TEXT = "string"; // ES 5: change to text
+ public static final String FIELD_TYPE_KEYWORD = "string"; // ES 5: change to keyword
public static final String STANDARD = "standard";
public static final String PATTERN = "pattern";
public static final String CUSTOM = "custom";
public static final String KEYWORD = "keyword";
public static final String CLASSIC = "classic";
+
public static final String TRUNCATE = "truncate";
public static final String SUB_FIELD_DELIMITER = ".";
-
public static final String TRIM = "trim";
public static final String LOWERCASE = "lowercase";
public static final String WHITESPACE = "whitespace";
import static org.sonar.server.es.DefaultIndexSettings.ANALYZER;
import static org.sonar.server.es.DefaultIndexSettings.ASCIIFOLDING;
import static org.sonar.server.es.DefaultIndexSettings.DELIMITER;
+import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_TEXT;
import static org.sonar.server.es.DefaultIndexSettings.FILTER;
import static org.sonar.server.es.DefaultIndexSettings.INDEX;
import static org.sonar.server.es.DefaultIndexSettings.KEYWORD;
import static org.sonar.server.es.DefaultIndexSettings.SEARCH_ANALYZER;
import static org.sonar.server.es.DefaultIndexSettings.STANDARD;
import static org.sonar.server.es.DefaultIndexSettings.STOP;
-import static org.sonar.server.es.DefaultIndexSettings.STRING;
import static org.sonar.server.es.DefaultIndexSettings.SUB_FIELD_DELIMITER;
import static org.sonar.server.es.DefaultIndexSettings.TOKENIZER;
import static org.sonar.server.es.DefaultIndexSettings.TRIM;
@Override
public SortedMap<String, String> fieldMapping() {
return ImmutableSortedMap.of(
- TYPE, STRING,
+ TYPE, FIELD_TYPE_TEXT,
INDEX, ANALYZED,
ANALYZER, getName());
}
@Override
public SortedMap<String, String> fieldMapping() {
return ImmutableSortedMap.of(
- TYPE, STRING,
+ TYPE, FIELD_TYPE_TEXT,
INDEX, ANALYZED,
ANALYZER, INDEX_GRAMS_ANALYZER.getName(),
SEARCH_ANALYZER, getName());
@Override
public SortedMap<String, String> fieldMapping() {
return ImmutableSortedMap.of(
- TYPE, STRING,
+ TYPE, FIELD_TYPE_TEXT,
INDEX, ANALYZED,
ANALYZER, INDEX_PREFIX_ANALYZER.getName(),
SEARCH_ANALYZER, getName());
@Override
public SortedMap<String, String> fieldMapping() {
return ImmutableSortedMap.of(
- TYPE, STRING,
+ TYPE, FIELD_TYPE_TEXT,
INDEX, ANALYZED,
ANALYZER, INDEX_PREFIX_CASE_INSENSITIVE_ANALYZER.getName(),
SEARCH_ANALYZER, getName());
@Override
public SortedMap<String, String> fieldMapping() {
return ImmutableSortedMap.of(
- TYPE, STRING,
+ TYPE, FIELD_TYPE_TEXT,
INDEX, ANALYZED,
ANALYZER, USER_INDEX_GRAMS_ANALYZER.getName(),
SEARCH_ANALYZER, getName());
@Override
public SortedMap<String, String> fieldMapping() {
return ImmutableSortedMap.of(
- TYPE, STRING,
+ TYPE, FIELD_TYPE_TEXT,
INDEX, ANALYZED,
ANALYZER, INDEX_WORDS_ANALYZER.getName(),
SEARCH_ANALYZER, getName());
import static java.lang.String.format;
import static org.sonar.server.es.DefaultIndexSettings.ANALYZED;
import static org.sonar.server.es.DefaultIndexSettings.ANALYZER;
+import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_KEYWORD;
+import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_TEXT;
import static org.sonar.server.es.DefaultIndexSettings.INDEX;
-import static org.sonar.server.es.DefaultIndexSettings.STRING;
import static org.sonar.server.es.DefaultIndexSettings.TYPE;
import static org.sonar.server.es.DefaultIndexSettingsElement.UUID_MODULE_ANALYZER;
return this;
}
- public StringFieldBuilder stringFieldBuilder(String fieldName) {
- return new StringFieldBuilder(this, fieldName);
+ public KeywordFieldBuilder keywordFieldBuilder(String fieldName) {
+ return new KeywordFieldBuilder(this, fieldName);
}
public NestedFieldBuilder nestedFieldBuilder(String fieldName) {
public NewIndexType createUuidPathField(String fieldName) {
return setProperty(fieldName, ImmutableSortedMap.of(
- TYPE, STRING,
+ TYPE, FIELD_TYPE_TEXT,
INDEX, ANALYZED,
ANALYZER, UUID_MODULE_ANALYZER.getName()));
}
/**
* Helper to define a string field in mapping of index type
*/
- public static class StringFieldBuilder {
+ public static class KeywordFieldBuilder {
private final NewIndexType indexType;
private final String fieldName;
private boolean disableSearch = false;
private boolean termVectorWithPositionOffsets = false;
private SortedMap<String, Object> subFields = Maps.newTreeMap();
- private StringFieldBuilder(NewIndexType indexType, String fieldName) {
+ private KeywordFieldBuilder(NewIndexType indexType, String fieldName) {
this.indexType = indexType;
this.fieldName = fieldName;
}
* Add a sub-field. A {@code SortedMap} is required for consistency of the index settings hash.
* @see IndexDefinitionHash
*/
- private StringFieldBuilder addSubField(String fieldName, SortedMap<String, String> fieldDefinition) {
+ private KeywordFieldBuilder addSubField(String fieldName, SortedMap<String, String> fieldDefinition) {
subFields.put(fieldName, fieldDefinition);
return this;
}
/**
* Add subfields, one for each analyzer.
*/
- public StringFieldBuilder addSubFields(DefaultIndexSettingsElement... analyzers) {
+ public KeywordFieldBuilder addSubFields(DefaultIndexSettingsElement... analyzers) {
Arrays.stream(analyzers)
- .forEach(analyzer -> addSubField(analyzer.getSubFieldSuffix(), analyzer.fieldMapping()));
+ .forEach(analyzer -> addSubField(analyzer.getSubFieldSuffix(), analyzer.fieldMapping()));
return this;
}
* https://www.elastic.co/guide/en/elasticsearch/reference/2.3/norms.html
* https://www.elastic.co/guide/en/elasticsearch/guide/current/scoring-theory.html#field-norm
*/
- public StringFieldBuilder disableNorms() {
+ public KeywordFieldBuilder disableNorms() {
this.disableNorms = true;
return this;
}
/**
* Position offset term vectors are required for the fast_vector_highlighter (fvh).
*/
- public StringFieldBuilder termVectorWithPositionOffsets() {
+ public KeywordFieldBuilder termVectorWithPositionOffsets() {
this.termVectorWithPositionOffsets = true;
return this;
}
* By default field is "not_analyzed": it is searchable, but index the value exactly
* as specified.
*/
- public StringFieldBuilder disableSearch() {
+ public KeywordFieldBuilder disableSearch() {
this.disableSearch = true;
return this;
}
Map<String, Object> hash = new TreeMap<>();
if (subFields.isEmpty()) {
hash.putAll(ImmutableMap.of(
- "type", "string",
- "index", disableSearch ? "no" : "not_analyzed",
- "norms", ImmutableMap.of("enabled", String.valueOf(!disableNorms))));
+ "type", FIELD_TYPE_KEYWORD,
+ "index", disableSearch ? "no" : "not_analyzed", // ES 5: change to false and true
+ "norms", ImmutableMap.of("enabled", String.valueOf(!disableNorms))));
} else {
hash.put("type", "multi_field");
Object subFieldMapping = entry.getValue();
if (subFieldMapping instanceof Map) {
entry.setValue(
- addFieldToMapping(
- (Map<String, String>) subFieldMapping,
- "term_vector", "with_positions_offsets"));
+ addFieldToMapping(
+ (Map<String, String>) subFieldMapping,
+ "term_vector", "with_positions_offsets"));
}
});
}
multiFields.put(fieldName, ImmutableMap.of(
- "type", "string",
- "index", "not_analyzed",
- "term_vector", termVectorWithPositionOffsets ? "with_positions_offsets" : "no",
- "norms", ImmutableMap.of("enabled", "false")));
+ "type", FIELD_TYPE_KEYWORD,
+ "index", "not_analyzed", // ES 5: change to true
+ "term_vector", termVectorWithPositionOffsets ? "with_positions_offsets" : "no",
+ "norms", ImmutableMap.of("enabled", "false")));
hash.put("fields", multiFields);
}
return this;
}
- public NestedFieldBuilder addStringField(String fieldName) {
+ public NestedFieldBuilder addKeywordField(String fieldName) {
return setProperty(fieldName, ImmutableMap.of(
- "type", "string",
+ "type", FIELD_TYPE_KEYWORD,
"index", "not_analyzed"));
}
NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_METADATA.getType());
- mapping.stringFieldBuilder(FIELD_VALUE).disableSearch().build();
+ mapping.keywordFieldBuilder(FIELD_VALUE).disableSearch().build();
}
}
type.requireProjectAuthorization();
type.setEnableSource(enableSource);
- type.stringFieldBuilder(FIELD_ISSUE_ASSIGNEE).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
- type.stringFieldBuilder(FIELD_ISSUE_AUTHOR_LOGIN).disableNorms().build();
- type.stringFieldBuilder(FIELD_ISSUE_COMPONENT_UUID).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_ASSIGNEE).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+ type.keywordFieldBuilder(FIELD_ISSUE_AUTHOR_LOGIN).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_COMPONENT_UUID).disableNorms().build();
type.createLongField(FIELD_ISSUE_EFFORT);
- type.stringFieldBuilder(FIELD_ISSUE_FILE_PATH).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+ type.keywordFieldBuilder(FIELD_ISSUE_FILE_PATH).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
type.createDateTimeField(FIELD_ISSUE_FUNC_CREATED_AT);
type.createDateTimeField(FIELD_ISSUE_FUNC_UPDATED_AT);
type.createDateTimeField(FIELD_ISSUE_FUNC_CLOSED_AT);
- type.stringFieldBuilder(FIELD_ISSUE_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
- type.stringFieldBuilder(FIELD_ISSUE_LANGUAGE).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+ type.keywordFieldBuilder(FIELD_ISSUE_LANGUAGE).disableNorms().build();
type.createIntegerField(FIELD_ISSUE_LINE);
- type.stringFieldBuilder(FIELD_ISSUE_MODULE_UUID).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_MODULE_UUID).disableNorms().build();
type.createUuidPathField(FIELD_ISSUE_MODULE_PATH);
- type.stringFieldBuilder(FIELD_ISSUE_ORGANIZATION_UUID).disableNorms().build();
- type.stringFieldBuilder(FIELD_ISSUE_PROJECT_UUID).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
- type.stringFieldBuilder(FIELD_ISSUE_DIRECTORY_PATH).disableNorms().build();
- type.stringFieldBuilder(FIELD_ISSUE_RESOLUTION).disableNorms().build();
- type.stringFieldBuilder(FIELD_ISSUE_RULE_KEY).disableNorms().build();
- type.stringFieldBuilder(FIELD_ISSUE_SEVERITY).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_ORGANIZATION_UUID).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_PROJECT_UUID).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+ type.keywordFieldBuilder(FIELD_ISSUE_DIRECTORY_PATH).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_RESOLUTION).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_RULE_KEY).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_SEVERITY).disableNorms().build();
type.createByteField(FIELD_ISSUE_SEVERITY_VALUE);
- type.stringFieldBuilder(FIELD_ISSUE_STATUS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
- type.stringFieldBuilder(FIELD_ISSUE_TAGS).disableNorms().build();
- type.stringFieldBuilder(FIELD_ISSUE_TYPE).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_STATUS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+ type.keywordFieldBuilder(FIELD_ISSUE_TAGS).disableNorms().build();
+ type.keywordFieldBuilder(FIELD_ISSUE_TYPE).disableNorms().build();
}
}
NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_PROJECT_MEASURES.getType())
.requireProjectAuthorization();
- mapping.stringFieldBuilder(FIELD_ORGANIZATION_UUID).build();
- mapping.stringFieldBuilder(FIELD_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
- mapping.stringFieldBuilder(FIELD_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build();
- mapping.stringFieldBuilder(FIELD_QUALITY_GATE_STATUS).build();
- mapping.stringFieldBuilder(FIELD_TAGS).build();
- mapping.stringFieldBuilder(FIELD_LANGUAGES).build();
+ mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUID).build();
+ mapping.keywordFieldBuilder(FIELD_KEY).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+ mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_GRAMS_ANALYZER).build();
+ mapping.keywordFieldBuilder(FIELD_QUALITY_GATE_STATUS).build();
+ mapping.keywordFieldBuilder(FIELD_TAGS).build();
+ mapping.keywordFieldBuilder(FIELD_LANGUAGES).build();
mapping.nestedFieldBuilder(FIELD_MEASURES)
- .addStringField(FIELD_MEASURES_KEY)
+ .addKeywordField(FIELD_MEASURES_KEY)
.addDoubleField(FIELD_MEASURES_VALUE)
.build();
mapping.createDateTimeField(FIELD_ANALYSED_AT);
activeRuleMapping.setEnableSource(enableSource);
activeRuleMapping.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType()));
- activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
- activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_REPOSITORY).build();
- activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_PROFILE_UUID).disableNorms().build();
- activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().build();
- activeRuleMapping.stringFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build();
+ activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
+ activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_REPOSITORY).build();
+ activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_PROFILE_UUID).disableNorms().build();
+ activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_INHERITANCE).disableNorms().build();
+ activeRuleMapping.keywordFieldBuilder(FIELD_ACTIVE_RULE_SEVERITY).disableNorms().build();
// Rule extension type
NewIndex.NewIndexType ruleExtensionType = index.createType(INDEX_TYPE_RULE_EXTENSION.getType());
ruleExtensionType.setEnableSource(enableSource);
ruleExtensionType.setAttribute("_parent", ImmutableMap.of("type", INDEX_TYPE_RULE.getType()));
- ruleExtensionType.stringFieldBuilder(FIELD_RULE_EXTENSION_SCOPE).disableNorms().build();
- ruleExtensionType.stringFieldBuilder(FIELD_RULE_EXTENSION_RULE_KEY).disableNorms().build();
- ruleExtensionType.stringFieldBuilder(FIELD_RULE_EXTENSION_TAGS).build();
+ ruleExtensionType.keywordFieldBuilder(FIELD_RULE_EXTENSION_SCOPE).disableNorms().build();
+ ruleExtensionType.keywordFieldBuilder(FIELD_RULE_EXTENSION_RULE_KEY).disableNorms().build();
+ ruleExtensionType.keywordFieldBuilder(FIELD_RULE_EXTENSION_TAGS).build();
// Rule type
NewIndex.NewIndexType ruleMapping = index.createType(INDEX_TYPE_RULE.getType());
ruleMapping.setEnableSource(enableSource);
- ruleMapping.stringFieldBuilder(FIELD_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
- ruleMapping.stringFieldBuilder(FIELD_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
- ruleMapping.stringFieldBuilder(FIELD_RULE_REPOSITORY).build();
- ruleMapping.stringFieldBuilder(FIELD_RULE_INTERNAL_KEY).disableNorms().disableSearch().build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_RULE_KEY).addSubFields(SORTABLE_ANALYZER).build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_REPOSITORY).build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_INTERNAL_KEY).disableNorms().disableSearch().build();
- ruleMapping.stringFieldBuilder(FIELD_RULE_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_WORDS_ANALYZER).build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_NAME).addSubFields(SORTABLE_ANALYZER, SEARCH_WORDS_ANALYZER).build();
ruleMapping.setProperty(FIELD_RULE_HTML_DESCRIPTION, ImmutableSortedMap.of(
- DefaultIndexSettings.TYPE, DefaultIndexSettings.STRING,
+ DefaultIndexSettings.TYPE, DefaultIndexSettings.FIELD_TYPE_TEXT,
DefaultIndexSettings.INDEX, DefaultIndexSettings.ANALYZED,
DefaultIndexSettings.ANALYZER, ENGLISH_HTML_ANALYZER.getName(),
DefaultIndexSettings.SEARCH_ANALYZER, ENGLISH_HTML_ANALYZER.getName()));
- ruleMapping.stringFieldBuilder(FIELD_RULE_SEVERITY).disableNorms().build();
- ruleMapping.stringFieldBuilder(FIELD_RULE_STATUS).disableNorms().build();
- ruleMapping.stringFieldBuilder(FIELD_RULE_LANGUAGE).disableNorms().build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_SEVERITY).disableNorms().build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_STATUS).disableNorms().build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_LANGUAGE).disableNorms().build();
ruleMapping.createBooleanField(FIELD_RULE_IS_TEMPLATE);
- ruleMapping.stringFieldBuilder(FIELD_RULE_TEMPLATE_KEY).disableNorms().build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_TEMPLATE_KEY).disableNorms().build();
- ruleMapping.stringFieldBuilder(FIELD_RULE_TYPE).disableNorms().build();
+ ruleMapping.keywordFieldBuilder(FIELD_RULE_TYPE).disableNorms().build();
ruleMapping.createLongField(FIELD_RULE_CREATED_AT);
ruleMapping.createLongField(FIELD_RULE_UPDATED_AT);
import org.sonar.server.es.IndexType;
import org.sonar.server.es.NewIndex;
+import static org.sonar.server.es.DefaultIndexSettings.FIELD_TYPE_KEYWORD;
+
public class TestIndexDefinition implements IndexDefinition {
public static final IndexType INDEX_TYPE_TEST = new IndexType("tests", "test");
NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_TEST.getType());
mapping.setAttribute("_routing", ImmutableMap.of("required", true));
- mapping.stringFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build();
- mapping.stringFieldBuilder(FIELD_FILE_UUID).disableNorms().build();
- mapping.stringFieldBuilder(FIELD_TEST_UUID).disableNorms().build();
- mapping.stringFieldBuilder(FIELD_NAME).disableNorms().disableSearch().build();
- mapping.stringFieldBuilder(FIELD_STATUS).disableNorms().disableSearch().build();
+ mapping.keywordFieldBuilder(FIELD_PROJECT_UUID).disableNorms().build();
+ mapping.keywordFieldBuilder(FIELD_FILE_UUID).disableNorms().build();
+ mapping.keywordFieldBuilder(FIELD_TEST_UUID).disableNorms().build();
+ mapping.keywordFieldBuilder(FIELD_NAME).disableNorms().disableSearch().build();
+ mapping.keywordFieldBuilder(FIELD_STATUS).disableNorms().disableSearch().build();
mapping.createLongField(FIELD_DURATION_IN_MS);
- mapping.stringFieldBuilder(FIELD_MESSAGE).disableNorms().disableSearch().build();
- mapping.stringFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().build();
+ mapping.keywordFieldBuilder(FIELD_MESSAGE).disableNorms().disableSearch().build();
+ mapping.keywordFieldBuilder(FIELD_STACKTRACE).disableNorms().disableSearch().build();
mapping.setProperty(FIELD_COVERED_FILES, ImmutableMap.of("type", "nested", "properties", ImmutableMap.of(
- FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", "string", "index", "not_analyzed"),
+ FIELD_COVERED_FILE_UUID, ImmutableMap.of("type", FIELD_TYPE_KEYWORD, "index", "not_analyzed"),
FIELD_COVERED_FILE_LINES, ImmutableMap.of("type", "integer"))));
mapping.createDateTimeField(FIELD_UPDATED_AT);
}
// type "user"
NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_USER.getType());
- mapping.stringFieldBuilder(FIELD_LOGIN).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
- mapping.stringFieldBuilder(FIELD_NAME).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
- mapping.stringFieldBuilder(FIELD_EMAIL).addSubFields(USER_SEARCH_GRAMS_ANALYZER, SORTABLE_ANALYZER).build();
+ mapping.keywordFieldBuilder(FIELD_LOGIN).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
+ mapping.keywordFieldBuilder(FIELD_NAME).addSubFields(USER_SEARCH_GRAMS_ANALYZER).build();
+ mapping.keywordFieldBuilder(FIELD_EMAIL).addSubFields(USER_SEARCH_GRAMS_ANALYZER, SORTABLE_ANALYZER).build();
mapping.createBooleanField(FIELD_ACTIVE);
- mapping.stringFieldBuilder(FIELD_SCM_ACCOUNTS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
- mapping.stringFieldBuilder(FIELD_ORGANIZATION_UUIDS).disableNorms().build();
+ mapping.keywordFieldBuilder(FIELD_SCM_ACCOUNTS).disableNorms().addSubFields(SORTABLE_ANALYZER).build();
+ mapping.keywordFieldBuilder(FIELD_ORGANIZATION_UUIDS).disableNorms().build();
}
}
// type "view"
NewIndex.NewIndexType mapping = index.createType(INDEX_TYPE_VIEW.getType());
- mapping.stringFieldBuilder(FIELD_UUID).disableNorms().build();
- mapping.stringFieldBuilder(FIELD_PROJECTS).disableNorms().build();
+ mapping.keywordFieldBuilder(FIELD_UUID).disableNorms().build();
+ mapping.keywordFieldBuilder(FIELD_PROJECTS).disableNorms().build();
}
}
public void define(IndexDefinitionContext context) {
NewIndex index = context.create("fakes");
NewIndex.NewIndexType mapping = index.createType("fake");
- mapping.stringFieldBuilder("key").build();
+ mapping.keywordFieldBuilder("key").build();
mapping.createDateTimeField("updatedAt");
}
}
public void define(IndexDefinitionContext context) {
NewIndex index = context.create("fakes");
NewIndex.NewIndexType mapping = index.createType("fake");
- mapping.stringFieldBuilder("key").build();
+ mapping.keywordFieldBuilder("key").build();
mapping.createDateTimeField("updatedAt");
mapping.createIntegerField("newField");
}
NewIndex newIndex = new NewIndex("fakes");
NewIndex.NewIndexType mapping = newIndex.createType("fake");
mapping.setAttribute("list_attr", Arrays.asList("foo", "bar"));
- mapping.stringFieldBuilder("key").build();
+ mapping.keywordFieldBuilder("key").build();
mapping.createDateTimeField("updatedAt");
return newIndex;
}
NewIndex index = new NewIndex("issues");
NewIndex.NewIndexType mapping = index.createType("issue");
mapping.setAttribute("dynamic", "true");
- mapping.setProperty("foo_field", ImmutableMap.of("type", "string"));
+ mapping.setProperty("foo_field", ImmutableMap.of("type", "string"));// ES 5: change to keyword
mapping.createBooleanField("boolean_field");
mapping.createByteField("byte_field");
mapping.createDateTimeField("dt_field");
assertThat(mapping).isNotNull();
assertThat(mapping.getAttributes().get("dynamic")).isEqualTo("true");
assertThat(mapping.getProperty("foo_field")).isInstanceOf(Map.class);
- assertThat((Map) mapping.getProperty("foo_field")).containsEntry("type", "string");
+ assertThat((Map) mapping.getProperty("foo_field")).containsEntry("type", "string");// ES 5: change to keyword
assertThat((Map) mapping.getProperty("byte_field")).isNotEmpty();
assertThat((Map) mapping.getProperty("double_field")).isNotEmpty();
assertThat((Map) mapping.getProperty("dt_field")).isNotEmpty();
public void define_string_field() {
NewIndex index = new NewIndex("issues");
NewIndex.NewIndexType mapping = index.createType("issue");
- mapping.stringFieldBuilder("basic_field").build();
- mapping.stringFieldBuilder("not_searchable_field").disableSearch().build();
- mapping.stringFieldBuilder("all_capabilities_field")
+ mapping.keywordFieldBuilder("basic_field").build();
+ mapping.keywordFieldBuilder("not_searchable_field").disableSearch().build();
+ mapping.keywordFieldBuilder("all_capabilities_field")
.addSubFields(
DefaultIndexSettingsElement.SEARCH_GRAMS_ANALYZER,
DefaultIndexSettingsElement.SEARCH_WORDS_ANALYZER,
.build();
Map<String, Object> props = (Map) mapping.getProperty("basic_field");
- assertThat(props.get("type")).isEqualTo("string");
+ assertThat(props.get("type")).isEqualTo("string");// ES 5: change to keyword
assertThat(props.get("index")).isEqualTo("not_analyzed");
assertThat(props.get("fields")).isNull();
props = (Map) mapping.getProperty("not_searchable_field");
- assertThat(props.get("type")).isEqualTo("string");
+ assertThat(props.get("type")).isEqualTo("string");// ES 5: change to keyword
assertThat(props.get("index")).isEqualTo("no");
assertThat(props.get("fields")).isNull();
NewIndex.NewIndexType mapping = index.createType("projectmeasures");
mapping.nestedFieldBuilder("measures")
- .addStringField("key")
+ .addKeywordField("key")
.addDoubleField("value")
.build();
Map<String, Object> result = (Map) mapping.getProperty("measures");
assertThat(result.get("type")).isEqualTo("nested");
Map<String, Map<String, Object>> subProperties = (Map) result.get("properties");
- assertThat(subProperties.get("key").get("type")).isEqualTo("string");
+ assertThat(subProperties.get("key").get("type")).isEqualTo("string"); // ES 5: change to "keyword
assertThat(subProperties.get("value").get("type")).isEqualTo("double");
}
public void use_default_doc_values() {
NewIndex index = new NewIndex("issues");
NewIndex.NewIndexType mapping = index.createType("issue");
- mapping.stringFieldBuilder("the_doc_value").build();
+ mapping.keywordFieldBuilder("the_doc_value").build();
Map<String, Object> props = (Map) mapping.getProperty("the_doc_value");
- assertThat(props.get("type")).isEqualTo("string");
+ assertThat(props.get("type")).isEqualTo("string");// ES 5: change to keyword
assertThat(props.get("doc_values")).isNull();
}
NewIndex.NewIndexType type = index.createType(FOO_TYPE)
.requireProjectAuthorization();
- type.stringFieldBuilder(FIELD_NAME).build();
- type.stringFieldBuilder(FIELD_PROJECT_UUID).build();
+ type.keywordFieldBuilder(FIELD_NAME).build();
+ type.keywordFieldBuilder(FIELD_PROJECT_UUID).build();
}
}