forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn about upcoming expanded fields limit
Starting with Elasticsearch 7.0, we limit the number of automatically expanded fields for the "all fields" mode ("default_field": "*") for the query_string and simple_query_string queries to 1024 fields (see elastic#26541). This change adds a deprecation warning to the QueryParserHelper where in the next major version we will throw an error to warn users of the upcoming change. Relates to elastic#26541
- Loading branch information
Christoph Büscher
committed
Oct 26, 2018
1 parent
7f56bb4
commit f24a9ca
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
server/src/test/java/org/elasticsearch/index/search/QueryParserHelperTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.index.search; | ||
|
||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.index.IndexService; | ||
import org.elasticsearch.index.mapper.MapperService; | ||
import org.elasticsearch.index.query.QueryShardContext; | ||
import org.elasticsearch.test.ESSingleNodeTestCase; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; | ||
|
||
public class QueryParserHelperTests extends ESSingleNodeTestCase { | ||
|
||
/** | ||
* Test that when {@link QueryParserHelper#resolveMappingFields(QueryShardContext, java.util.Map, String)} exceeds | ||
* the limit of 1024 fields, we emit a warning | ||
*/ | ||
public void testLimitOnExpandedFields() throws Exception { | ||
|
||
XContentBuilder builder = jsonBuilder(); | ||
builder.startObject(); | ||
builder.startObject("type1"); | ||
builder.startObject("properties"); | ||
for (int i = 0; i < 1025; i++) { | ||
builder.startObject("field" + i).field("type", "text").endObject(); | ||
} | ||
builder.endObject(); // properties | ||
builder.endObject(); // type1 | ||
builder.endObject(); | ||
IndexService indexService = createIndex("toomanyfields", Settings.builder() | ||
.put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), 1200).build(), | ||
"type1", builder); | ||
client().prepareIndex("toomanyfields", "type1", "1").setSource("field171", "foo bar baz").get(); | ||
|
||
QueryShardContext queryShardContext = indexService.newQueryShardContext( | ||
randomInt(20), null, () -> { throw new UnsupportedOperationException(); }, null); | ||
|
||
QueryParserHelper.resolveMappingField(queryShardContext, "*", 1.0f, true, false); | ||
assertWarnings("Field expansion matches too many fields, got: 1025. A limit of 1024 will be enforced starting with " | ||
+ "version 7.0 of Elasticsearch. Lowering the number of fields will be necessary before upgrading."); | ||
|
||
QueryParserHelper.resolveMappingFields(queryShardContext,Collections.singletonMap("*", 1.0f)); | ||
assertWarnings("Field expansion matches too many fields, got: 1025. A limit of 1024 will be enforced starting with " | ||
+ "version 7.0 of Elasticsearch. Lowering the number of fields will be necessary before upgrading."); | ||
} | ||
} |