Query DSL: deprecate _name and boost in short variants of queries
As discussed in #11744 this is the last step to unify parsing of boost and _name. Those fields are supported only in long version of queries, while we sometimes parse them when wwe shouldn't, inconsistently. Closes #11744 Closes #12966
This commit is contained in:
parent
793fcb6998
commit
dc807f294e
|
@ -943,7 +943,8 @@ public class Strings {
|
||||||
boolean changed = false;
|
boolean changed = false;
|
||||||
for (int i = 0; i < value.length(); i++) {
|
for (int i = 0; i < value.length(); i++) {
|
||||||
char c = value.charAt(i);
|
char c = value.charAt(i);
|
||||||
if (c == '_') {
|
//e.g. _name stays as-is, _first_name becomes _firstName
|
||||||
|
if (c == '_' && i > 0) {
|
||||||
if (!changed) {
|
if (!changed) {
|
||||||
if (sb != null) {
|
if (sb != null) {
|
||||||
sb.setLength(0);
|
sb.setLength(0);
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.search.MultiTermQuery;
|
import org.apache.lucene.search.MultiTermQuery;
|
||||||
import org.apache.lucene.search.PrefixQuery;
|
import org.apache.lucene.search.PrefixQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.BytesRefs;
|
import org.elasticsearch.common.lucene.BytesRefs;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -38,6 +39,8 @@ public class PrefixQueryParser implements QueryParser {
|
||||||
|
|
||||||
public static final String NAME = "prefix";
|
public static final String NAME = "prefix";
|
||||||
|
|
||||||
|
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of prefix query");
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public PrefixQueryParser() {
|
public PrefixQueryParser() {
|
||||||
}
|
}
|
||||||
|
@ -84,7 +87,7 @@ public class PrefixQueryParser implements QueryParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if (parseContext.parseFieldMatcher().match(currentFieldName, NAME_FIELD)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
} else {
|
} else {
|
||||||
fieldName = currentFieldName;
|
fieldName = currentFieldName;
|
||||||
|
|
|
@ -40,6 +40,7 @@ public class RangeQueryParser implements QueryParser {
|
||||||
|
|
||||||
public static final String NAME = "range";
|
public static final String NAME = "range";
|
||||||
private static final ParseField FIELDDATA_FIELD = new ParseField("fielddata").withAllDeprecated("[no replacement]");
|
private static final ParseField FIELDDATA_FIELD = new ParseField("fielddata").withAllDeprecated("[no replacement]");
|
||||||
|
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of range query");
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RangeQueryParser() {
|
public RangeQueryParser() {
|
||||||
|
@ -109,7 +110,7 @@ public class RangeQueryParser implements QueryParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if (parseContext.parseFieldMatcher().match(currentFieldName, NAME_FIELD)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FIELDDATA_FIELD)) {
|
} else if (parseContext.parseFieldMatcher().match(currentFieldName, FIELDDATA_FIELD)) {
|
||||||
// ignore
|
// ignore
|
||||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.lucene.search.MultiTermQuery;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.RegexpQuery;
|
import org.apache.lucene.search.RegexpQuery;
|
||||||
import org.apache.lucene.util.automaton.Operations;
|
import org.apache.lucene.util.automaton.Operations;
|
||||||
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.BytesRefs;
|
import org.elasticsearch.common.lucene.BytesRefs;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -41,6 +42,8 @@ public class RegexpQueryParser implements QueryParser {
|
||||||
|
|
||||||
public static final int DEFAULT_FLAGS_VALUE = RegexpFlag.ALL.value();
|
public static final int DEFAULT_FLAGS_VALUE = RegexpFlag.ALL.value();
|
||||||
|
|
||||||
|
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of regexp query");
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public RegexpQueryParser() {
|
public RegexpQueryParser() {
|
||||||
}
|
}
|
||||||
|
@ -96,7 +99,7 @@ public class RegexpQueryParser implements QueryParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if (parseContext.parseFieldMatcher().match(currentFieldName, NAME_FIELD)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
} else {
|
} else {
|
||||||
fieldName = currentFieldName;
|
fieldName = currentFieldName;
|
||||||
|
|
|
@ -22,10 +22,10 @@ package org.elasticsearch.index.query;
|
||||||
import org.apache.lucene.index.Term;
|
import org.apache.lucene.index.Term;
|
||||||
import org.apache.lucene.search.Query;
|
import org.apache.lucene.search.Query;
|
||||||
import org.apache.lucene.search.TermQuery;
|
import org.apache.lucene.search.TermQuery;
|
||||||
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.lucene.BytesRefs;
|
import org.elasticsearch.common.lucene.BytesRefs;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.mapper.FieldMapper;
|
|
||||||
import org.elasticsearch.index.mapper.MappedFieldType;
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -37,6 +37,9 @@ public class TermQueryParser implements QueryParser {
|
||||||
|
|
||||||
public static final String NAME = "term";
|
public static final String NAME = "term";
|
||||||
|
|
||||||
|
private static final ParseField NAME_FIELD = new ParseField("_name").withAllDeprecated("query name is not supported in short version of term query");
|
||||||
|
private static final ParseField BOOST_FIELD = new ParseField("boost").withAllDeprecated("boost is not supported in short version of term query");
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public TermQueryParser() {
|
public TermQueryParser() {
|
||||||
}
|
}
|
||||||
|
@ -85,9 +88,9 @@ public class TermQueryParser implements QueryParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (token.isValue()) {
|
} else if (token.isValue()) {
|
||||||
if ("_name".equals(currentFieldName)) {
|
if (parseContext.parseFieldMatcher().match(currentFieldName, NAME_FIELD)) {
|
||||||
queryName = parser.text();
|
queryName = parser.text();
|
||||||
} else if ("boost".equals(currentFieldName)) {
|
} else if (parseContext.parseFieldMatcher().match(currentFieldName, BOOST_FIELD)) {
|
||||||
boost = parser.floatValue();
|
boost = parser.floatValue();
|
||||||
} else {
|
} else {
|
||||||
if (fieldName != null) {
|
if (fieldName != null) {
|
||||||
|
|
|
@ -29,6 +29,8 @@ public class StringsTests extends ESTestCase {
|
||||||
assertEquals("fooBar", Strings.toCamelCase("foo_bar"));
|
assertEquals("fooBar", Strings.toCamelCase("foo_bar"));
|
||||||
assertEquals("fooBarFooBar", Strings.toCamelCase("foo_bar_foo_bar"));
|
assertEquals("fooBarFooBar", Strings.toCamelCase("foo_bar_foo_bar"));
|
||||||
assertEquals("fooBar", Strings.toCamelCase("foo_bar_"));
|
assertEquals("fooBar", Strings.toCamelCase("foo_bar_"));
|
||||||
|
assertEquals("_foo", Strings.toCamelCase("_foo"));
|
||||||
|
assertEquals("_fooBar", Strings.toCamelCase("_foo_bar_"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSubstring() {
|
public void testSubstring() {
|
||||||
|
|
|
@ -54,9 +54,7 @@ import java.nio.file.Path;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
import static org.elasticsearch.common.settings.Settings.settingsBuilder;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.*;
|
||||||
import static org.hamcrest.Matchers.instanceOf;
|
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -249,7 +247,7 @@ public class AnalysisModuleTests extends ESTestCase {
|
||||||
fail("This should fail with IllegalArgumentException because the analyzers name starts with _");
|
fail("This should fail with IllegalArgumentException because the analyzers name starts with _");
|
||||||
} catch (ProvisionException e) {
|
} catch (ProvisionException e) {
|
||||||
assertTrue(e.getCause() instanceof IllegalArgumentException);
|
assertTrue(e.getCause() instanceof IllegalArgumentException);
|
||||||
assertThat(e.getCause().getMessage(), equalTo("analyzer name must not start with '_'. got \"_invalid_name\""));
|
assertThat(e.getCause().getMessage(), either(equalTo("analyzer name must not start with '_'. got \"_invalid_name\"")).or(equalTo("analyzer name must not start with '_'. got \"_invalidName\"")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue