Skip to content

Commit

Permalink
Disable _all by default
Browse files Browse the repository at this point in the history
This change disables the _all meta field by default.

Now that we have the "all-fields" method of query execution, we can save both
indexing time and disk space by disabling it.

_all can no longer be configured for indices created after 6.0.

Relates to elastic#20925 and elastic#21341
Resolves elastic#19784
  • Loading branch information
dakrone committed Jan 11, 2017
1 parent fed2a1a commit 7a18bb5
Show file tree
Hide file tree
Showing 51 changed files with 234 additions and 1,414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.lucene.index.IndexableField;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.Query;
import org.elasticsearch.Version;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.lucene.all.AllEntries;
import org.elasticsearch.common.lucene.all.AllField;
Expand Down Expand Up @@ -52,7 +53,7 @@ public class AllFieldMapper extends MetadataFieldMapper {
public static class Defaults {
public static final String NAME = AllFieldMapper.NAME;
public static final String INDEX_NAME = AllFieldMapper.NAME;
public static final EnabledAttributeMapper ENABLED = EnabledAttributeMapper.UNSET_ENABLED;
public static final EnabledAttributeMapper ENABLED = EnabledAttributeMapper.UNSET_DISABLED;
public static final int POSITION_INCREMENT_GAP = 100;

public static final MappedFieldType FIELD_TYPE = new AllFieldType();
Expand Down Expand Up @@ -103,6 +104,11 @@ public static class TypeParser implements MetadataFieldMapper.TypeParser {
@Override
public MetadataFieldMapper.Builder<?,?> parse(String name, Map<String, Object> node,
ParserContext parserContext) throws MapperParsingException {
if (node.isEmpty() == false &&
parserContext.indexVersionCreated().onOrAfter(Version.V_6_0_0_alpha1_UNRELEASED)) {
throw new IllegalArgumentException("[_all] is disabled in 6.0. As a replacement, you can use an [copy_to] " +
"on mapping fields to create your own catch all field.");
}
Builder builder = new Builder(parserContext.mapperService().fullName(NAME));
builder.fieldType().setIndexAnalyzer(parserContext.getIndexAnalyzers().getDefaultIndexAnalyzer());
builder.fieldType().setSearchAnalyzer(parserContext.getIndexAnalyzers().getDefaultSearchAnalyzer());
Expand Down
39 changes: 12 additions & 27 deletions core/src/test/java/org/elasticsearch/get/GetActionIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -682,30 +682,6 @@ public void testGetFieldsComplexField() throws Exception {
assertThat(getResponse.getField(field).getValues().get(1).toString(), equalTo("value2"));
}

public void testGetAllField() throws Exception {
assertAcked(prepareCreate("test")
.addAlias(new Alias("alias"))
.addMapping("my-type1", jsonBuilder()
.startObject()
.startObject("my-type1")
.startObject("_all")
.field("store", true)
.endObject()
.startObject("properties")
.startObject("some_field")
.field("type", "text")
.endObject()
.endObject()
.endObject()
.endObject()));
index("test", "my-type1", "1", "some_field", "some text");
refresh();

GetResponse getResponse = client().prepareGet(indexOrAlias(), "my-type1", "1").setStoredFields("_all").get();
assertNotNull(getResponse.getField("_all").getValue());
assertThat(getResponse.getField("_all").getValue().toString(), equalTo("some text"));
}

public void testUngeneratedFieldsThatAreNeverStored() throws IOException {
String createIndexSource = "{\n" +
" \"settings\": {\n" +
Expand Down Expand Up @@ -804,7 +780,7 @@ public void testUngeneratedFieldsNotPartOfSourceStored() throws IOException {

public void testGeneratedStringFieldsUnstored() throws IOException {
indexSingleDocumentWithStringFieldsGeneratedFromText(false, randomBoolean());
String[] fieldsList = {"_all", "_field_names"};
String[] fieldsList = {"_field_names"};
// before refresh - document is only in translog
assertGetFieldsAlwaysNull(indexOrAlias(), "doc", "1", fieldsList);
refresh();
Expand All @@ -817,7 +793,7 @@ public void testGeneratedStringFieldsUnstored() throws IOException {

public void testGeneratedStringFieldsStored() throws IOException {
indexSingleDocumentWithStringFieldsGeneratedFromText(true, randomBoolean());
String[] fieldsList = {"_all"};
String[] fieldsList = {"text1", "text2"};
String[] alwaysNotStoredFieldsList = {"_field_names"};
assertGetFieldsAlwaysWorks(indexOrAlias(), "doc", "1", fieldsList);
assertGetFieldsNull(indexOrAlias(), "doc", "1", alwaysNotStoredFieldsList);
Expand All @@ -838,7 +814,16 @@ void indexSingleDocumentWithStringFieldsGeneratedFromText(boolean stored, boolea
" \"mappings\": {\n" +
" \"doc\": {\n" +
" \"_source\" : {\"enabled\" : " + sourceEnabled + "}," +
" \"_all\" : {\"enabled\" : true, \"store\":\"" + storedString + "\" }" +
" \"properties\": {\n" +
" \"text1\": {\n" +
" \"type\": \"text\",\n" +
" \"store\": \"" + storedString + "\"" +
" },\n" +
" \"text2\": {\n" +
" \"type\": \"text\",\n" +
" \"store\": \"" + storedString + "\"" +
" }" +
" }\n" +
" }\n" +
" }\n" +
"}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,6 @@ public void testCoerce() throws Exception {

protected abstract void doTestCoerce(String type) throws IOException;

public void testIncludeInAll() throws Exception {
for (String type : TYPES) {
doTestIncludeInAll(type);
}
}

protected abstract void doTestIncludeInAll(String type) throws Exception;

public void testNullValue() throws IOException {
for (String type : TYPES) {
doTestNullValue(type);
Expand Down

This file was deleted.

Loading

0 comments on commit 7a18bb5

Please sign in to comment.