Percolator keyword fields should not store norms (#58899)

The refactoring in #57666 inadvertently enabled norms on two of the percolator subfields,
leading to an increase in memory usage. This commit disables norms on these fields again.
This commit is contained in:
Alan Woodward 2020-07-02 13:58:55 +01:00 committed by Alan Woodward
parent fc5b2b2be4
commit 0cd1dc3143
4 changed files with 10 additions and 3 deletions

View File

@ -413,6 +413,7 @@ public class PercolatorFieldMapper extends FieldMapper {
private static final FieldType INDEXED_KEYWORD = new FieldType();
static {
INDEXED_KEYWORD.setTokenized(false);
INDEXED_KEYWORD.setOmitNorms(true);
INDEXED_KEYWORD.setIndexOptions(IndexOptions.DOCS);
INDEXED_KEYWORD.freeze();
}

View File

@ -665,7 +665,11 @@ public class PercolatorFieldMapperTests extends ESSingleNodeTestCase {
.endObject().endObject()),
XContentType.JSON));
assertThat(doc.rootDoc().getFields().size(), equalTo(12)); // also includes all other meta fields
BytesRef queryBuilderAsBytes = doc.rootDoc().getField("object_field.query_field.query_builder_field").binaryValue();
IndexableField queryBuilderField = doc.rootDoc().getField("object_field.query_field.query_builder_field");
assertTrue(queryBuilderField.fieldType().omitNorms());
IndexableField extractionResultField = doc.rootDoc().getField("object_field.query_field.extraction_result");
assertTrue(extractionResultField.fieldType().omitNorms());
BytesRef queryBuilderAsBytes = queryBuilderField.binaryValue();
assertQueryBuilder(queryBuilderAsBytes, queryBuilder);
doc = mapperService.documentMapper(typeName).parse(new SourceToParse("test", typeName, "1",

View File

@ -20,8 +20,8 @@
package org.elasticsearch.index.mapper;
import com.carrotsearch.hppc.ObjectArrayList;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.StoredField;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.DocValuesFieldExistsQuery;
@ -59,6 +59,7 @@ public class BinaryFieldMapper extends FieldMapper {
static {
FIELD_TYPE.setIndexOptions(IndexOptions.NONE);
FIELD_TYPE.setOmitNorms(true);
FIELD_TYPE.freeze();
}
}
@ -188,7 +189,7 @@ public class BinaryFieldMapper extends FieldMapper {
return;
}
if (fieldType.stored()) {
context.doc().add(new Field(fieldType().name(), value, fieldType));
context.doc().add(new StoredField(fieldType().name(), value));
}
if (fieldType().hasDocValues()) {

View File

@ -34,6 +34,7 @@ public abstract class CustomDocValuesField implements IndexableField {
public static final FieldType TYPE = new FieldType();
static {
TYPE.setDocValuesType(DocValuesType.BINARY);
TYPE.setOmitNorms(true);
TYPE.freeze();
}