AbstractQueryTestCase should run without type less often (#28936)
This commit changes the randomization to always create an index with a type. It also adds a way to create a query shard context that maps to an index with no type registered in order to explicitely test cases where there is no type.
This commit is contained in:
parent
57876bfeb9
commit
8e5f281b27
|
@ -45,12 +45,10 @@ public class FeatureQueryBuilderTests extends AbstractQueryTestCase<FeatureQuery
|
|||
|
||||
@Override
|
||||
protected void initializeAdditionalMappings(MapperService mapperService) throws IOException {
|
||||
for (String type : getCurrentTypes()) {
|
||||
mapperService.merge(type, new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(type,
|
||||
"my_feature_field", "type=feature",
|
||||
"my_negative_feature_field", "type=feature,positive_score_impact=false",
|
||||
"my_feature_vector_field", "type=feature_vector"))), MapperService.MergeReason.MAPPING_UPDATE);
|
||||
}
|
||||
mapperService.merge("_doc", new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc",
|
||||
"my_feature_field", "type=feature",
|
||||
"my_negative_feature_field", "type=feature,positive_score_impact=false",
|
||||
"my_feature_vector_field", "type=feature_vector"))), MapperService.MergeReason.MAPPING_UPDATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,7 +85,7 @@ public class FeatureQueryBuilderTests extends AbstractQueryTestCase<FeatureQuery
|
|||
if (mayUseNegativeField) {
|
||||
fields.add("my_negative_feature_field");
|
||||
}
|
||||
|
||||
|
||||
final String field = randomFrom(fields);
|
||||
return new FeatureQueryBuilder(field, function);
|
||||
}
|
||||
|
@ -99,7 +97,6 @@ public class FeatureQueryBuilderTests extends AbstractQueryTestCase<FeatureQuery
|
|||
}
|
||||
|
||||
public void testDefaultScoreFunction() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"feature\" : {\n" +
|
||||
" \"field\": \"my_feature_field\"\n" +
|
||||
|
@ -110,7 +107,6 @@ public class FeatureQueryBuilderTests extends AbstractQueryTestCase<FeatureQuery
|
|||
}
|
||||
|
||||
public void testIllegalField() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"feature\" : {\n" +
|
||||
" \"field\": \"" + STRING_FIELD_NAME + "\"\n" +
|
||||
|
@ -121,7 +117,6 @@ public class FeatureQueryBuilderTests extends AbstractQueryTestCase<FeatureQuery
|
|||
}
|
||||
|
||||
public void testIllegalCombination() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"feature\" : {\n" +
|
||||
" \"field\": \"my_negative_feature_field\",\n" +
|
||||
|
|
|
@ -89,7 +89,6 @@ public class DisMaxQueryBuilderTests extends AbstractQueryTestCase<DisMaxQueryBu
|
|||
}
|
||||
|
||||
public void testToQueryInnerPrefixQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String queryAsString = "{\n" +
|
||||
" \"dis_max\":{\n" +
|
||||
" \"queries\":[\n" +
|
||||
|
|
|
@ -68,11 +68,7 @@ public class ExistsQueryBuilderTests extends AbstractQueryTestCase<ExistsQueryBu
|
|||
Collection<String> fields = context.getQueryShardContext().simpleMatchToIndexNames(fieldPattern);
|
||||
Collection<String> mappedFields = fields.stream().filter((field) -> context.getQueryShardContext().getObjectMapper(field) != null
|
||||
|| context.getQueryShardContext().getMapperService().fullName(field) != null).collect(Collectors.toList());
|
||||
if (getCurrentTypes().length == 0) {
|
||||
assertThat(query, instanceOf(MatchNoDocsQuery.class));
|
||||
MatchNoDocsQuery matchNoDocsQuery = (MatchNoDocsQuery) query;
|
||||
assertThat(matchNoDocsQuery.toString(null), containsString("Missing types in \"exists\" query."));
|
||||
} else if (context.mapperService().getIndexSettings().getIndexVersionCreated().before(Version.V_6_1_0)) {
|
||||
if (context.mapperService().getIndexSettings().getIndexVersionCreated().before(Version.V_6_1_0)) {
|
||||
if (fields.size() == 1) {
|
||||
assertThat(query, instanceOf(ConstantScoreQuery.class));
|
||||
ConstantScoreQuery constantScoreQuery = (ConstantScoreQuery) query;
|
||||
|
|
|
@ -105,7 +105,6 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
|
|||
}
|
||||
|
||||
public void testToQueryWithStringField() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"fuzzy\":{\n" +
|
||||
" \"" + STRING_FIELD_NAME + "\":{\n" +
|
||||
|
@ -128,7 +127,6 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
|
|||
}
|
||||
|
||||
public void testToQueryWithStringFieldDefinedFuzziness() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"fuzzy\":{\n" +
|
||||
" \"" + STRING_FIELD_NAME + "\":{\n" +
|
||||
|
@ -151,7 +149,6 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
|
|||
}
|
||||
|
||||
public void testToQueryWithStringFieldDefinedWrongFuzziness() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String queryMissingFuzzinessUpLimit = "{\n" +
|
||||
" \"fuzzy\":{\n" +
|
||||
" \"" + STRING_FIELD_NAME + "\":{\n" +
|
||||
|
@ -214,7 +211,6 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
|
|||
}
|
||||
|
||||
public void testToQueryWithNumericField() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"fuzzy\":{\n" +
|
||||
" \"" + INT_FIELD_NAME + "\":{\n" +
|
||||
|
@ -299,7 +295,6 @@ public class FuzzyQueryBuilderTests extends AbstractQueryTestCase<FuzzyQueryBuil
|
|||
}
|
||||
|
||||
public void testToQueryWithTranspositions() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = new FuzzyQueryBuilder(STRING_FIELD_NAME, "text").toQuery(createShardContext());
|
||||
assertThat(query, instanceOf(FuzzyQuery.class));
|
||||
assertEquals(FuzzyQuery.defaultTranspositions, ((FuzzyQuery)query).getTranspositions());
|
||||
|
|
|
@ -39,7 +39,6 @@ import java.io.IOException;
|
|||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBoundingBoxQueryBuilder> {
|
||||
/** Randomly generate either NaN or one of the two infinity values. */
|
||||
|
@ -110,16 +109,12 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
assertEquals("cannot parse type from null string", e.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testToQuery() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
super.testToQuery();
|
||||
}
|
||||
|
||||
public void testExceptionOnMissingTypes() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length == 0);
|
||||
QueryShardException e = expectThrows(QueryShardException.class, super::testToQuery);
|
||||
assertThat(e.getMessage(), startsWith("failed to find geo_point field [mapped_geo_point"));
|
||||
public void testExceptionOnMissingTypes() {
|
||||
QueryShardContext context = createShardContextWithNoType();
|
||||
GeoBoundingBoxQueryBuilder qb = createTestQueryBuilder();
|
||||
qb.ignoreUnmapped(false);
|
||||
QueryShardException e = expectThrows(QueryShardException.class, () -> qb.toQuery(context));
|
||||
assertEquals("failed to find geo_point field [" + qb.fieldName() + "]", e.getMessage());
|
||||
}
|
||||
|
||||
public void testBrokenCoordinateCannotBeSet() {
|
||||
|
@ -295,7 +290,6 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery1() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_bounding_box\":{\n" +
|
||||
" \"" + GEO_POINT_FIELD_NAME+ "\":{\n" +
|
||||
|
@ -308,7 +302,6 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery2() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_bounding_box\":{\n" +
|
||||
" \"" + GEO_POINT_FIELD_NAME+ "\":{\n" +
|
||||
|
@ -327,7 +320,6 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery3() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_bounding_box\":{\n" +
|
||||
" \"" + GEO_POINT_FIELD_NAME+ "\":{\n" +
|
||||
|
@ -340,7 +332,6 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery4() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_bounding_box\":{\n" +
|
||||
" \"" + GEO_POINT_FIELD_NAME+ "\":{\n" +
|
||||
|
@ -353,7 +344,6 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery5() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_bounding_box\":{\n" +
|
||||
" \"" + GEO_POINT_FIELD_NAME+ "\":{\n" +
|
||||
|
@ -366,7 +356,6 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery6() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_bounding_box\":{\n" +
|
||||
" \"" + GEO_POINT_FIELD_NAME+ "\":{\n" +
|
||||
|
@ -513,7 +502,6 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
}
|
||||
|
||||
public void testHonorsCoercion() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_bounding_box\": {\n" +
|
||||
" \"validation_method\": \"COERCE\",\n" +
|
||||
|
@ -534,7 +522,6 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase<GeoBo
|
|||
|
||||
@Override
|
||||
public void testMustRewrite() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
super.testMustRewrite();
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
*/
|
||||
@Override
|
||||
public void testToQuery() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
super.testToQuery();
|
||||
}
|
||||
|
||||
|
@ -148,7 +147,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery1() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":\"12mi\",\n" +
|
||||
|
@ -162,7 +160,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery2() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":\"12mi\",\n" +
|
||||
|
@ -173,7 +170,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery3() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":\"12mi\",\n" +
|
||||
|
@ -184,7 +180,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery4() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":\"12mi\",\n" +
|
||||
|
@ -195,7 +190,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery5() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":12,\n" +
|
||||
|
@ -210,7 +204,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery6() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":\"12\",\n" +
|
||||
|
@ -225,7 +218,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery7() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":\"19.312128\",\n" +
|
||||
|
@ -239,7 +231,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery8() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":19.312128,\n" +
|
||||
|
@ -253,7 +244,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery9() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":\"19.312128\",\n" +
|
||||
|
@ -268,7 +258,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery10() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":19.312128,\n" +
|
||||
|
@ -283,7 +272,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery11() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":\"19.312128km\",\n" +
|
||||
|
@ -297,7 +285,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery12() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_distance\":{\n" +
|
||||
" \"distance\":\"12mi\",\n" +
|
||||
|
@ -312,7 +299,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
}
|
||||
|
||||
private void assertGeoDistanceRangeQuery(String query, double lat, double lon, double distance, DistanceUnit distanceUnit) throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query parsedQuery = parseQuery(query).toQuery(createShardContext());
|
||||
// TODO: what can we check?
|
||||
}
|
||||
|
@ -336,12 +322,6 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase<GeoDista
|
|||
assertEquals(json, 12000.0, parsed.distance(), 0.0001);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testMustRewrite() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
super.testMustRewrite();
|
||||
}
|
||||
|
||||
public void testIgnoreUnmapped() throws IOException {
|
||||
final GeoDistanceQueryBuilder queryBuilder = new GeoDistanceQueryBuilder("unmapped").point(0.0, 0.0).distance("20m");
|
||||
queryBuilder.ignoreUnmapped(true);
|
||||
|
|
|
@ -62,17 +62,6 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
|
|||
// todo LatLonPointInPolygon is package private
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden here to ensure the test is only run if at least one type is
|
||||
* present in the mappings. Geo queries do not execute if the field is not
|
||||
* explicitly mapped
|
||||
*/
|
||||
@Override
|
||||
public void testToQuery() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
super.testToQuery();
|
||||
}
|
||||
|
||||
private static List<GeoPoint> randomPolygon() {
|
||||
ShapeBuilder<?, ?> shapeBuilder = null;
|
||||
// This is a temporary fix because sometimes the RandomShapeGenerator
|
||||
|
@ -138,7 +127,6 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery1() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_polygon\":{\n" +
|
||||
" \"" + GEO_POINT_FIELD_NAME + "\":{\n" +
|
||||
|
@ -154,7 +142,6 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery2() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_polygon\":{\n" +
|
||||
" \"" + GEO_POINT_FIELD_NAME + "\":{\n" +
|
||||
|
@ -179,7 +166,6 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery3() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_polygon\":{\n" +
|
||||
" \"" + GEO_POINT_FIELD_NAME + "\":{\n" +
|
||||
|
@ -195,7 +181,6 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
|
|||
}
|
||||
|
||||
public void testParsingAndToQuery4() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"geo_polygon\":{\n" +
|
||||
" \"" + GEO_POINT_FIELD_NAME + "\":{\n" +
|
||||
|
@ -234,12 +219,6 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
|
|||
assertEquals(json, 4, parsed.points().size());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testMustRewrite() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
super.testMustRewrite();
|
||||
}
|
||||
|
||||
public void testIgnoreUnmapped() throws IOException {
|
||||
List<GeoPoint> polygon = randomPolygon();
|
||||
final GeoPolygonQueryBuilder queryBuilder = new GeoPolygonQueryBuilder("unmapped", polygon);
|
||||
|
@ -255,7 +234,6 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase<GeoPolygo
|
|||
}
|
||||
|
||||
public void testPointValidation() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext context = createShardContext();
|
||||
String queryInvalidLat = "{\n" +
|
||||
" \"geo_polygon\":{\n" +
|
||||
|
|
|
@ -153,17 +153,6 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
|
|||
assertThat(query, anyOf(instanceOf(BooleanQuery.class), instanceOf(ConstantScoreQuery.class)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden here to ensure the test is only run if at least one type is
|
||||
* present in the mappings. Geo queries do not execute if the field is not
|
||||
* explicitly mapped
|
||||
*/
|
||||
@Override
|
||||
public void testToQuery() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
super.testToQuery();
|
||||
}
|
||||
|
||||
public void testNoFieldName() throws Exception {
|
||||
ShapeBuilder<?, ?> shape = RandomShapeGenerator.createShapeWithin(random(), null);
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> new GeoShapeQueryBuilder(null, shape));
|
||||
|
@ -279,7 +268,6 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase<GeoShapeQue
|
|||
}
|
||||
|
||||
public void testWrongFieldType() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
ShapeType shapeType = ShapeType.randomType(random());
|
||||
ShapeBuilder<?, ?> shape = RandomShapeGenerator.createShapeWithin(random(), null, shapeType);
|
||||
final GeoShapeQueryBuilder queryBuilder = new GeoShapeQueryBuilder(STRING_FIELD_NAME, shape);
|
||||
|
|
|
@ -40,23 +40,17 @@ public class IdsQueryBuilderTests extends AbstractQueryTestCase<IdsQueryBuilder>
|
|||
|
||||
@Override
|
||||
protected IdsQueryBuilder doCreateTestQueryBuilder() {
|
||||
String[] types;
|
||||
if (getCurrentTypes() != null && getCurrentTypes().length > 0 && randomBoolean()) {
|
||||
int numberOfTypes = randomIntBetween(1, getCurrentTypes().length);
|
||||
types = new String[numberOfTypes];
|
||||
for (int i = 0; i < numberOfTypes; i++) {
|
||||
if (frequently()) {
|
||||
types[i] = randomFrom(getCurrentTypes());
|
||||
} else {
|
||||
types[i] = randomAlphaOfLengthBetween(1, 10);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (randomBoolean()) {
|
||||
types = new String[]{MetaData.ALL};
|
||||
final String type;
|
||||
if (randomBoolean()) {
|
||||
if (frequently()) {
|
||||
type = "_doc";
|
||||
} else {
|
||||
types = new String[0];
|
||||
type = randomAlphaOfLengthBetween(1, 10);
|
||||
}
|
||||
} else if (randomBoolean()) {
|
||||
type = MetaData.ALL;
|
||||
} else {
|
||||
type = null;
|
||||
}
|
||||
int numberOfIds = randomIntBetween(0, 10);
|
||||
String[] ids = new String[numberOfIds];
|
||||
|
@ -64,8 +58,8 @@ public class IdsQueryBuilderTests extends AbstractQueryTestCase<IdsQueryBuilder>
|
|||
ids[i] = randomAlphaOfLengthBetween(1, 10);
|
||||
}
|
||||
IdsQueryBuilder query;
|
||||
if (types.length > 0 || randomBoolean()) {
|
||||
query = new IdsQueryBuilder().types(types);
|
||||
if (type != null && randomBoolean()) {
|
||||
query = new IdsQueryBuilder().types(type);
|
||||
query.addIds(ids);
|
||||
} else {
|
||||
query = new IdsQueryBuilder();
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.test.AbstractBuilderTestCase.STRING_ALIAS_FIELD_NAME;
|
||||
import static org.hamcrest.CoreMatchers.either;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
@ -42,11 +43,8 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||
public class MatchPhrasePrefixQueryBuilderTests extends AbstractQueryTestCase<MatchPhrasePrefixQueryBuilder> {
|
||||
@Override
|
||||
protected MatchPhrasePrefixQueryBuilder doCreateTestQueryBuilder() {
|
||||
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME, BOOLEAN_FIELD_NAME,
|
||||
INT_FIELD_NAME, DOUBLE_FIELD_NAME, DATE_FIELD_NAME);
|
||||
if (fieldName.equals(DATE_FIELD_NAME)) {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
}
|
||||
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME, BOOLEAN_FIELD_NAME, INT_FIELD_NAME,
|
||||
DOUBLE_FIELD_NAME, DATE_FIELD_NAME);
|
||||
Object value;
|
||||
if (isTextField(fieldName)) {
|
||||
int terms = randomIntBetween(0, 3);
|
||||
|
@ -119,7 +117,6 @@ public class MatchPhrasePrefixQueryBuilderTests extends AbstractQueryTestCase<Ma
|
|||
}
|
||||
|
||||
public void testPhraseOnFieldWithNoTerms() {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
MatchPhrasePrefixQueryBuilder matchQuery = new MatchPhrasePrefixQueryBuilder(DATE_FIELD_NAME, "three term phrase");
|
||||
matchQuery.analyzer("whitespace");
|
||||
expectThrows(IllegalArgumentException.class, () -> matchQuery.doToQuery(createShardContext()));
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.test.AbstractBuilderTestCase.STRING_ALIAS_FIELD_NAME;
|
||||
import static org.hamcrest.CoreMatchers.either;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
@ -45,11 +46,8 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||
public class MatchPhraseQueryBuilderTests extends AbstractQueryTestCase<MatchPhraseQueryBuilder> {
|
||||
@Override
|
||||
protected MatchPhraseQueryBuilder doCreateTestQueryBuilder() {
|
||||
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME, BOOLEAN_FIELD_NAME,
|
||||
INT_FIELD_NAME, DOUBLE_FIELD_NAME, DATE_FIELD_NAME);
|
||||
if (fieldName.equals(DATE_FIELD_NAME)) {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
}
|
||||
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME, BOOLEAN_FIELD_NAME, INT_FIELD_NAME,
|
||||
DOUBLE_FIELD_NAME, DATE_FIELD_NAME);
|
||||
Object value;
|
||||
if (isTextField(fieldName)) {
|
||||
int terms = randomIntBetween(0, 3);
|
||||
|
|
|
@ -61,11 +61,8 @@ import static org.hamcrest.Matchers.notNullValue;
|
|||
public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuilder> {
|
||||
@Override
|
||||
protected MatchQueryBuilder doCreateTestQueryBuilder() {
|
||||
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME, BOOLEAN_FIELD_NAME,
|
||||
INT_FIELD_NAME, DOUBLE_FIELD_NAME, DATE_FIELD_NAME);
|
||||
if (fieldName.equals(DATE_FIELD_NAME)) {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
}
|
||||
String fieldName = randomFrom(STRING_FIELD_NAME, STRING_ALIAS_FIELD_NAME, BOOLEAN_FIELD_NAME, INT_FIELD_NAME,
|
||||
DOUBLE_FIELD_NAME, DATE_FIELD_NAME);
|
||||
Object value;
|
||||
if (isTextField(fieldName)) {
|
||||
int terms = randomIntBetween(0, 3);
|
||||
|
@ -279,7 +276,6 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
|
|||
}
|
||||
|
||||
public void testFuzzinessOnNonStringField() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
MatchQueryBuilder query = new MatchQueryBuilder(INT_FIELD_NAME, 42);
|
||||
query.fuzziness(randomFuzziness(INT_FIELD_NAME));
|
||||
QueryShardContext context = createShardContext();
|
||||
|
@ -300,7 +296,6 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
|
|||
}
|
||||
|
||||
public void testExactOnUnsupportedField() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
MatchQueryBuilder query = new MatchQueryBuilder(GEO_POINT_FIELD_NAME, "2,3");
|
||||
QueryShardContext context = createShardContext();
|
||||
QueryShardException e = expectThrows(QueryShardException.class, () -> query.toQuery(context));
|
||||
|
@ -352,7 +347,6 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
|
|||
}
|
||||
|
||||
public void testExceptionUsingAnalyzerOnNumericField() {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext shardContext = createShardContext();
|
||||
MatchQueryBuilder matchQueryBuilder = new MatchQueryBuilder(DOUBLE_FIELD_NAME, 6.075210893508043E-4);
|
||||
matchQueryBuilder.analyzer("simple");
|
||||
|
@ -371,7 +365,6 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
|
|||
}
|
||||
|
||||
public void testMatchPhrasePrefixWithBoost() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext context = createShardContext();
|
||||
assumeTrue("test runs only when the index version is on or after V_5_0_0_alpha1",
|
||||
context.indexVersionCreated().onOrAfter(Version.V_5_0_0_alpha1));
|
||||
|
@ -395,7 +388,6 @@ public class MatchQueryBuilderTests extends AbstractQueryTestCase<MatchQueryBuil
|
|||
}
|
||||
|
||||
public void testLenientPhraseQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext context = createShardContext();
|
||||
MatchQuery b = new MatchQuery(context);
|
||||
b.setLenient(true);
|
||||
|
|
|
@ -294,7 +294,6 @@ public class MoreLikeThisQueryBuilderTests extends AbstractQueryTestCase<MoreLik
|
|||
}
|
||||
|
||||
public void testUnsupportedFields() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String unsupportedField = randomFrom(INT_FIELD_NAME, DOUBLE_FIELD_NAME, DATE_FIELD_NAME);
|
||||
MoreLikeThisQueryBuilder queryBuilder = new MoreLikeThisQueryBuilder(new String[] {unsupportedField}, new String[]{"some text"}, null)
|
||||
.failOnUnsupportedField(true);
|
||||
|
|
|
@ -65,9 +65,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
protected MultiMatchQueryBuilder doCreateTestQueryBuilder() {
|
||||
String fieldName = randomFrom(STRING_FIELD_NAME, INT_FIELD_NAME, DOUBLE_FIELD_NAME, BOOLEAN_FIELD_NAME, DATE_FIELD_NAME,
|
||||
MISSING_FIELD_NAME, MISSING_WILDCARD_FIELD_NAME);
|
||||
if (fieldName.equals(DATE_FIELD_NAME)) {
|
||||
assumeTrue("test with date fields runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
}
|
||||
|
||||
final Object value;
|
||||
if (fieldName.equals(STRING_FIELD_NAME)) {
|
||||
|
@ -173,7 +170,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
}
|
||||
|
||||
public void testToQueryBoost() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext shardContext = createShardContext();
|
||||
MultiMatchQueryBuilder multiMatchQueryBuilder = new MultiMatchQueryBuilder("test");
|
||||
multiMatchQueryBuilder.field(STRING_FIELD_NAME, 5f);
|
||||
|
@ -191,7 +187,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
}
|
||||
|
||||
public void testToQueryMultipleTermsBooleanQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = multiMatchQuery("test1 test2").field(STRING_FIELD_NAME).useDisMax(false).toQuery(createShardContext());
|
||||
assertThat(query, instanceOf(BooleanQuery.class));
|
||||
BooleanQuery bQuery = (BooleanQuery) query;
|
||||
|
@ -201,7 +196,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
}
|
||||
|
||||
public void testToQueryMultipleFieldsDisableDismax() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = multiMatchQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2).useDisMax(false).toQuery(createShardContext());
|
||||
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
|
||||
DisjunctionMaxQuery dQuery = (DisjunctionMaxQuery) query;
|
||||
|
@ -212,7 +206,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
}
|
||||
|
||||
public void testToQueryMultipleFieldsDisMaxQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = multiMatchQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2).useDisMax(true).toQuery(createShardContext());
|
||||
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
|
||||
DisjunctionMaxQuery disMaxQuery = (DisjunctionMaxQuery) query;
|
||||
|
@ -225,7 +218,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
}
|
||||
|
||||
public void testToQueryFieldsWildcard() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = multiMatchQuery("test").field("mapped_str*").useDisMax(false).toQuery(createShardContext());
|
||||
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
|
||||
DisjunctionMaxQuery dQuery = (DisjunctionMaxQuery) query;
|
||||
|
@ -237,7 +229,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
}
|
||||
|
||||
public void testToQueryFieldMissing() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
assertThat(multiMatchQuery("test").field(MISSING_WILDCARD_FIELD_NAME).toQuery(createShardContext()), instanceOf(MatchNoDocsQuery.class));
|
||||
assertThat(multiMatchQuery("test").field(MISSING_FIELD_NAME).toQuery(createShardContext()), instanceOf(MatchNoDocsQuery.class));
|
||||
}
|
||||
|
@ -307,7 +298,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
}
|
||||
|
||||
public void testExceptionUsingAnalyzerOnNumericField() {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext shardContext = createShardContext();
|
||||
MultiMatchQueryBuilder multiMatchQueryBuilder = new MultiMatchQueryBuilder(6.075210893508043E-4);
|
||||
multiMatchQueryBuilder.field(DOUBLE_FIELD_NAME);
|
||||
|
@ -317,7 +307,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
}
|
||||
|
||||
public void testFuzzinessOnNonStringField() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
MultiMatchQueryBuilder query = new MultiMatchQueryBuilder(42).field(INT_FIELD_NAME).field(BOOLEAN_FIELD_NAME);
|
||||
query.fuzziness(randomFuzziness(INT_FIELD_NAME));
|
||||
QueryShardContext context = createShardContext();
|
||||
|
@ -336,8 +325,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
}
|
||||
|
||||
public void testToFuzzyQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
|
||||
MultiMatchQueryBuilder qb = new MultiMatchQueryBuilder("text").field(STRING_FIELD_NAME);
|
||||
qb.fuzziness(Fuzziness.TWO);
|
||||
qb.prefixLength(2);
|
||||
|
@ -351,7 +338,6 @@ public class MultiMatchQueryBuilderTests extends AbstractQueryTestCase<MultiMatc
|
|||
}
|
||||
|
||||
public void testDefaultField() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext context = createShardContext();
|
||||
MultiMatchQueryBuilder builder = new MultiMatchQueryBuilder("hello");
|
||||
// should pass because we set lenient to true when default field is `*`
|
||||
|
|
|
@ -109,7 +109,6 @@ public class PrefixQueryBuilderTests extends AbstractQueryTestCase<PrefixQueryBu
|
|||
}
|
||||
|
||||
public void testNumeric() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
PrefixQueryBuilder query = prefixQuery(INT_FIELD_NAME, "12*");
|
||||
QueryShardContext context = createShardContext();
|
||||
QueryShardException e = expectThrows(QueryShardException.class,
|
||||
|
|
|
@ -401,7 +401,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryTermQuery() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = queryStringQuery("test").defaultField(STRING_FIELD_NAME).toQuery(createShardContext());
|
||||
assertThat(query, instanceOf(TermQuery.class));
|
||||
TermQuery termQuery = (TermQuery) query;
|
||||
|
@ -409,7 +408,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryPhraseQuery() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = queryStringQuery("\"term1 term2\"")
|
||||
.defaultField(STRING_FIELD_NAME)
|
||||
.phraseSlop(3)
|
||||
|
@ -423,7 +421,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryBoosts() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext shardContext = createShardContext();
|
||||
QueryStringQueryBuilder queryStringQuery = queryStringQuery(STRING_FIELD_NAME + ":boosted^2");
|
||||
Query query = queryStringQuery.toQuery(shardContext);
|
||||
|
@ -463,7 +460,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryMultipleTermsBooleanQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = queryStringQuery("test1 test2").field(STRING_FIELD_NAME)
|
||||
.toQuery(createShardContext());
|
||||
assertThat(query, instanceOf(BooleanQuery.class));
|
||||
|
@ -476,7 +472,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryMultipleFieldsBooleanQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = queryStringQuery("test").field(STRING_FIELD_NAME)
|
||||
.field(STRING_FIELD_NAME_2)
|
||||
.toQuery(createShardContext());
|
||||
|
@ -490,7 +485,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryMultipleFieldsDisMaxQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = queryStringQuery("test").field(STRING_FIELD_NAME).field(STRING_FIELD_NAME_2)
|
||||
.toQuery(createShardContext());
|
||||
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
|
||||
|
@ -501,7 +495,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryFieldsWildcard() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = queryStringQuery("test").field("mapped_str*").toQuery(createShardContext());
|
||||
assertThat(query, instanceOf(DisjunctionMaxQuery.class));
|
||||
DisjunctionMaxQuery dQuery = (DisjunctionMaxQuery) query;
|
||||
|
@ -515,7 +508,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryDisMaxQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = queryStringQuery("test").field(STRING_FIELD_NAME, 2.2f)
|
||||
.field(STRING_FIELD_NAME_2)
|
||||
.toQuery(createShardContext());
|
||||
|
@ -527,7 +519,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryWildcardQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
for (Operator op : Operator.values()) {
|
||||
BooleanClause.Occur defaultOp = op.toBooleanClauseOccur();
|
||||
QueryStringQueryParser queryParser = new QueryStringQueryParser(createShardContext(), STRING_FIELD_NAME);
|
||||
|
@ -550,7 +541,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryWilcardQueryWithSynonyms() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
for (Operator op : Operator.values()) {
|
||||
BooleanClause.Occur defaultOp = op.toBooleanClauseOccur();
|
||||
QueryStringQueryParser queryParser = new QueryStringQueryParser(createShardContext(), STRING_FIELD_NAME);
|
||||
|
@ -583,7 +573,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryWithGraph() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
for (Operator op : Operator.values()) {
|
||||
BooleanClause.Occur defaultOp = op.toBooleanClauseOccur();
|
||||
QueryStringQueryParser queryParser = new QueryStringQueryParser(createShardContext(), STRING_FIELD_NAME);
|
||||
|
@ -698,7 +687,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryRegExpQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = queryStringQuery("/foo*bar/").defaultField(STRING_FIELD_NAME)
|
||||
.maxDeterminizedStates(5000)
|
||||
.toQuery(createShardContext());
|
||||
|
@ -708,7 +696,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryRegExpQueryTooComplex() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryStringQueryBuilder queryBuilder = queryStringQuery("/[ac]*a[ac]{50,200}/").defaultField(STRING_FIELD_NAME);
|
||||
|
||||
TooComplexToDeterminizeException e = expectThrows(TooComplexToDeterminizeException.class,
|
||||
|
@ -721,7 +708,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
* Validates that {@code max_determinized_states} can be parsed and lowers the allowed number of determinized states.
|
||||
*/
|
||||
public void testToQueryRegExpQueryMaxDeterminizedStatesParsing() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||
builder.startObject(); {
|
||||
builder.startObject("query_string"); {
|
||||
|
@ -744,7 +730,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
* Validates that {@code max_determinized_states} can be parsed and lowers the allowed number of determinized states.
|
||||
*/
|
||||
public void testEnabledPositionIncrements() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
|
||||
XContentBuilder builder = JsonXContent.contentBuilder();
|
||||
builder.startObject(); {
|
||||
|
@ -762,8 +747,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryFuzzyQueryAutoFuziness() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
|
||||
int length = randomIntBetween(1, 10);
|
||||
StringBuilder queryString = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
|
@ -788,7 +771,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testFuzzyNumeric() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryStringQueryBuilder query = queryStringQuery("12~0.2").defaultField(INT_FIELD_NAME);
|
||||
QueryShardContext context = createShardContext();
|
||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||
|
@ -800,7 +782,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testPrefixNumeric() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryStringQueryBuilder query = queryStringQuery("12*").defaultField(INT_FIELD_NAME);
|
||||
QueryShardContext context = createShardContext();
|
||||
QueryShardException e = expectThrows(QueryShardException.class,
|
||||
|
@ -812,7 +793,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testExactGeo() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryStringQueryBuilder query = queryStringQuery("2,3").defaultField(GEO_POINT_FIELD_NAME);
|
||||
QueryShardContext context = createShardContext();
|
||||
QueryShardException e = expectThrows(QueryShardException.class,
|
||||
|
@ -824,7 +804,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testTimezone() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String queryAsString = "{\n" +
|
||||
" \"query_string\":{\n" +
|
||||
" \"time_zone\":\"Europe/Paris\",\n" +
|
||||
|
@ -846,7 +825,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryBooleanQueryMultipleBoosts() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
int numBoosts = randomIntBetween(2, 10);
|
||||
float[] boosts = new float[numBoosts + 1];
|
||||
String queryStringPrefix = "";
|
||||
|
@ -885,7 +863,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryPhraseQueryBoostAndSlop() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryStringQueryBuilder queryStringQueryBuilder =
|
||||
new QueryStringQueryBuilder("\"test phrase\"~2").field(STRING_FIELD_NAME, 5f);
|
||||
Query query = queryStringQueryBuilder.toQuery(createShardContext());
|
||||
|
@ -899,7 +876,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryWildcardNonExistingFields() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryStringQueryBuilder queryStringQueryBuilder =
|
||||
new QueryStringQueryBuilder("foo bar").field("invalid*");
|
||||
Query query = queryStringQueryBuilder.toQuery(createShardContext());
|
||||
|
@ -918,7 +894,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToQueryTextParsing() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
{
|
||||
QueryStringQueryBuilder queryBuilder =
|
||||
new QueryStringQueryBuilder("foo bar")
|
||||
|
@ -1017,16 +992,15 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
QueryShardContext context = createShardContext();
|
||||
QueryStringQueryBuilder queryBuilder = new QueryStringQueryBuilder(STRING_FIELD_NAME + ":*");
|
||||
Query query = queryBuilder.toQuery(context);
|
||||
if (getCurrentTypes().length > 0) {
|
||||
if (context.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0)
|
||||
&& (context.fieldMapper(STRING_FIELD_NAME).omitNorms() == false)) {
|
||||
assertThat(query, equalTo(new ConstantScoreQuery(new NormsFieldExistsQuery(STRING_FIELD_NAME))));
|
||||
} else {
|
||||
assertThat(query, equalTo(new ConstantScoreQuery(new TermQuery(new Term("_field_names", STRING_FIELD_NAME)))));
|
||||
}
|
||||
if (context.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0)
|
||||
&& (context.fieldMapper(STRING_FIELD_NAME).omitNorms() == false)) {
|
||||
assertThat(query, equalTo(new ConstantScoreQuery(new NormsFieldExistsQuery(STRING_FIELD_NAME))));
|
||||
} else {
|
||||
assertThat(query, equalTo(new MatchNoDocsQuery()));
|
||||
assertThat(query, equalTo(new ConstantScoreQuery(new TermQuery(new Term("_field_names", STRING_FIELD_NAME)))));
|
||||
}
|
||||
QueryShardContext contextNoType = createShardContextWithNoType();
|
||||
query = queryBuilder.toQuery(contextNoType);
|
||||
assertThat(query, equalTo(new MatchNoDocsQuery()));
|
||||
|
||||
queryBuilder = new QueryStringQueryBuilder("*:*");
|
||||
query = queryBuilder.toQuery(context);
|
||||
|
@ -1040,7 +1014,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testDisabledFieldNamesField() throws Exception {
|
||||
assumeTrue("No types", getCurrentTypes().length > 0);
|
||||
QueryShardContext context = createShardContext();
|
||||
context.getMapperService().merge("_doc",
|
||||
new CompressedXContent(
|
||||
|
@ -1098,7 +1071,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testExpandedTerms() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
// Prefix
|
||||
Query query = new QueryStringQueryBuilder("aBc*")
|
||||
.field(STRING_FIELD_NAME)
|
||||
|
@ -1161,7 +1133,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testLenientRewriteToMatchNoDocs() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
// Term
|
||||
Query query = new QueryStringQueryBuilder("hello")
|
||||
.field(INT_FIELD_NAME)
|
||||
|
@ -1207,7 +1178,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testDefaultField() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext context = createShardContext();
|
||||
context.getIndexSettings().updateIndexMetaData(
|
||||
newIndexMeta("index", context.getIndexSettings().getSettings(), Settings.builder().putList("index.query.default_field",
|
||||
|
@ -1233,7 +1203,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
* the quote analyzer should overwrite any other forced analyzer in quoted parts of the query
|
||||
*/
|
||||
public void testQuoteAnalyzer() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
// Prefix
|
||||
Query query = new QueryStringQueryBuilder("ONE \"TWO THREE\"")
|
||||
.field(STRING_FIELD_NAME)
|
||||
|
@ -1252,7 +1221,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testQuoteFieldSuffix() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext context = createShardContext();
|
||||
assertEquals(new TermQuery(new Term(STRING_FIELD_NAME, "bar")),
|
||||
new QueryStringQueryBuilder("bar")
|
||||
|
@ -1283,8 +1251,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testToFuzzyQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
|
||||
Query query = new QueryStringQueryBuilder("text~2")
|
||||
.field(STRING_FIELD_NAME)
|
||||
.fuzzyPrefixLength(2)
|
||||
|
@ -1296,7 +1262,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testWithStopWords() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = new QueryStringQueryBuilder("the quick fox")
|
||||
.field(STRING_FIELD_NAME)
|
||||
.analyzer("stop")
|
||||
|
@ -1309,7 +1274,6 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase<QueryStr
|
|||
}
|
||||
|
||||
public void testWithPrefixStopWords() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = new QueryStringQueryBuilder("the* quick fox")
|
||||
.field(STRING_FIELD_NAME)
|
||||
.analyzer("stop")
|
||||
|
|
|
@ -133,26 +133,20 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
|
|||
String expectedFieldName = expectedFieldName(queryBuilder.fieldName());
|
||||
if (queryBuilder.from() == null && queryBuilder.to() == null) {
|
||||
final Query expectedQuery;
|
||||
if (getCurrentTypes().length > 0) {
|
||||
if (context.mapperService().getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0)
|
||||
&& context.mapperService().fullName(queryBuilder.fieldName()).hasDocValues()) {
|
||||
expectedQuery = new ConstantScoreQuery(new DocValuesFieldExistsQuery(expectedFieldName));
|
||||
} else if (context.mapperService().getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0)
|
||||
&& context.mapperService().fullName(queryBuilder.fieldName()).omitNorms() == false) {
|
||||
expectedQuery = new ConstantScoreQuery(new NormsFieldExistsQuery(expectedFieldName));
|
||||
} else {
|
||||
expectedQuery = new ConstantScoreQuery(new TermQuery(new Term(FieldNamesFieldMapper.NAME, expectedFieldName)));
|
||||
}
|
||||
if (context.mapperService().getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0)
|
||||
&& context.mapperService().fullName(queryBuilder.fieldName()).hasDocValues()) {
|
||||
expectedQuery = new ConstantScoreQuery(new DocValuesFieldExistsQuery(expectedFieldName));
|
||||
} else if (context.mapperService().getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0) &&
|
||||
context.mapperService().fullName(queryBuilder.fieldName()).omitNorms() == false) {
|
||||
expectedQuery = new ConstantScoreQuery(new NormsFieldExistsQuery(expectedFieldName));
|
||||
} else {
|
||||
expectedQuery = new MatchNoDocsQuery("no mappings yet");
|
||||
expectedQuery = new ConstantScoreQuery(new TermQuery(new Term(FieldNamesFieldMapper.NAME, expectedFieldName)));
|
||||
}
|
||||
assertThat(query, equalTo(expectedQuery));
|
||||
|
||||
} else if (getCurrentTypes().length == 0 ||
|
||||
(expectedFieldName.equals(DATE_FIELD_NAME) == false
|
||||
&& expectedFieldName.equals(INT_FIELD_NAME) == false
|
||||
&& expectedFieldName.equals(DATE_RANGE_FIELD_NAME) == false
|
||||
&& expectedFieldName.equals(INT_RANGE_FIELD_NAME) == false)) {
|
||||
} else if (expectedFieldName.equals(DATE_FIELD_NAME) == false &&
|
||||
expectedFieldName.equals(INT_FIELD_NAME) == false &&
|
||||
expectedFieldName.equals(DATE_RANGE_FIELD_NAME) == false &&
|
||||
expectedFieldName.equals(INT_RANGE_FIELD_NAME) == false) {
|
||||
assertThat(query, instanceOf(TermRangeQuery.class));
|
||||
TermRangeQuery termRangeQuery = (TermRangeQuery) query;
|
||||
assertThat(termRangeQuery.getField(), equalTo(expectedFieldName));
|
||||
|
@ -165,7 +159,7 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
|
|||
query = ((IndexOrDocValuesQuery) query).getIndexQuery();
|
||||
assertThat(query, instanceOf(PointRangeQuery.class));
|
||||
MapperService mapperService = context.getQueryShardContext().getMapperService();
|
||||
MappedFieldType mappedFieldType = mapperService.fullName(DATE_FIELD_NAME);
|
||||
MappedFieldType mappedFieldType = mapperService.fullName(expectedFieldName);
|
||||
final Long fromInMillis;
|
||||
final Long toInMillis;
|
||||
// we have to normalize the incoming value into milliseconds since it could be literally anything
|
||||
|
@ -257,7 +251,6 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
|
|||
}
|
||||
|
||||
public void testToQueryNumericField() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query parsedQuery = rangeQuery(INT_FIELD_NAME).from(23).to(54).includeLower(true).includeUpper(false).toQuery(createShardContext());
|
||||
// since age is automatically registered in data, we encode it as numeric
|
||||
assertThat(parsedQuery, instanceOf(IndexOrDocValuesQuery.class));
|
||||
|
@ -267,7 +260,6 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
|
|||
}
|
||||
|
||||
public void testDateRangeQueryFormat() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
// We test 01/01/2012 from gte and 2030 for lt
|
||||
String query = "{\n" +
|
||||
" \"range\" : {\n" +
|
||||
|
@ -302,7 +294,6 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
|
|||
}
|
||||
|
||||
public void testDateRangeBoundaries() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"range\" : {\n" +
|
||||
" \"" + DATE_FIELD_NAME + "\" : {\n" +
|
||||
|
@ -339,7 +330,6 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
|
|||
}
|
||||
|
||||
public void testDateRangeQueryTimezone() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String query = "{\n" +
|
||||
" \"range\" : {\n" +
|
||||
" \"" + DATE_FIELD_NAME + "\" : {\n" +
|
||||
|
@ -427,19 +417,19 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase<RangeQueryBuil
|
|||
assertThat(rewrittenRange.to(), equalTo(null));
|
||||
|
||||
// Range query with open bounds rewrite to an exists query
|
||||
final Query luceneQuery = rewrittenRange.toQuery(queryShardContext);
|
||||
Query luceneQuery = rewrittenRange.toQuery(queryShardContext);
|
||||
final Query expectedQuery;
|
||||
if (getCurrentTypes().length > 0) {
|
||||
if (queryShardContext.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0)
|
||||
&& queryShardContext.fieldMapper(query.fieldName()).hasDocValues()) {
|
||||
expectedQuery = new ConstantScoreQuery(new DocValuesFieldExistsQuery(query.fieldName()));
|
||||
} else {
|
||||
expectedQuery = new ConstantScoreQuery(new TermQuery(new Term(FieldNamesFieldMapper.NAME, query.fieldName())));
|
||||
}
|
||||
if (queryShardContext.getIndexSettings().getIndexVersionCreated().onOrAfter(Version.V_6_1_0)
|
||||
&& queryShardContext.fieldMapper(query.fieldName()).hasDocValues()) {
|
||||
expectedQuery = new ConstantScoreQuery(new DocValuesFieldExistsQuery(query.fieldName()));
|
||||
} else {
|
||||
expectedQuery = new MatchNoDocsQuery("no mappings yet");
|
||||
expectedQuery = new ConstantScoreQuery(new TermQuery(new Term(FieldNamesFieldMapper.NAME, query.fieldName())));
|
||||
}
|
||||
assertThat(luceneQuery, equalTo(expectedQuery));
|
||||
|
||||
QueryShardContext queryShardContextWithUnkType = createShardContextWithNoType();
|
||||
luceneQuery = rewrittenRange.toQuery(queryShardContextWithUnkType);
|
||||
assertThat(luceneQuery, equalTo(new MatchNoDocsQuery("no mappings yet")));
|
||||
}
|
||||
|
||||
public void testRewriteDateToMatchAllWithTimezoneAndFormat() throws IOException {
|
||||
|
|
|
@ -116,7 +116,6 @@ public class RegexpQueryBuilderTests extends AbstractQueryTestCase<RegexpQueryBu
|
|||
}
|
||||
|
||||
public void testNumeric() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
RegexpQueryBuilder query = new RegexpQueryBuilder(INT_FIELD_NAME, "12");
|
||||
QueryShardContext context = createShardContext();
|
||||
QueryShardException e = expectThrows(QueryShardException.class, () -> query.toQuery(context));
|
||||
|
|
|
@ -247,11 +247,8 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
assertThat(queryBuilder.fields().size(), equalTo(0));
|
||||
QueryShardContext shardContext = createShardContext();
|
||||
|
||||
// the remaining tests requires either a mapping that we register with types in base test setup
|
||||
if (getCurrentTypes().length > 0) {
|
||||
Query luceneQuery = queryBuilder.toQuery(shardContext);
|
||||
assertThat(luceneQuery, anyOf(instanceOf(BooleanQuery.class), instanceOf(DisjunctionMaxQuery.class)));
|
||||
}
|
||||
Query luceneQuery = queryBuilder.toQuery(shardContext);
|
||||
assertThat(luceneQuery, anyOf(instanceOf(BooleanQuery.class), instanceOf(DisjunctionMaxQuery.class)));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -315,7 +312,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testToQueryBoost() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext shardContext = createShardContext();
|
||||
SimpleQueryStringBuilder simpleQueryStringBuilder = new SimpleQueryStringBuilder("test");
|
||||
simpleQueryStringBuilder.field(STRING_FIELD_NAME, 5);
|
||||
|
@ -380,7 +376,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testMinimumShouldMatch() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext shardContext = createShardContext();
|
||||
int numberOfTerms = randomIntBetween(1, 4);
|
||||
StringBuilder queryString = new StringBuilder();
|
||||
|
@ -421,13 +416,10 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
simpleQueryStringBuilder.field("_index");
|
||||
Query query = simpleQueryStringBuilder.toQuery(shardContext);
|
||||
assertThat(query, notNullValue());
|
||||
if (getCurrentTypes().length > 0) {
|
||||
assertThat(query, instanceOf(MatchAllDocsQuery.class));
|
||||
}
|
||||
assertThat(query, instanceOf(MatchAllDocsQuery.class));
|
||||
}
|
||||
|
||||
public void testExpandedTerms() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
// Prefix
|
||||
Query query = new SimpleQueryStringBuilder("aBc*")
|
||||
.field(STRING_FIELD_NAME)
|
||||
|
@ -456,7 +448,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testAnalyzeWildcard() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
SimpleQueryStringQueryParser.Settings settings = new SimpleQueryStringQueryParser.Settings();
|
||||
settings.analyzeWildcard(true);
|
||||
SimpleQueryStringQueryParser parser = new SimpleQueryStringQueryParser(new StandardAnalyzer(),
|
||||
|
@ -480,7 +471,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testAnalyzerWildcardWithSynonyms() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
SimpleQueryStringQueryParser.Settings settings = new SimpleQueryStringQueryParser.Settings();
|
||||
settings.analyzeWildcard(true);
|
||||
SimpleQueryStringQueryParser parser = new SimpleQueryStringQueryParser(new MockRepeatAnalyzer(),
|
||||
|
@ -512,7 +502,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testAnalyzerWithGraph() {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
SimpleQueryStringQueryParser.Settings settings = new SimpleQueryStringQueryParser.Settings();
|
||||
settings.analyzeWildcard(true);
|
||||
SimpleQueryStringQueryParser parser = new SimpleQueryStringQueryParser(new MockSynonymAnalyzer(),
|
||||
|
@ -557,7 +546,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testQuoteFieldSuffix() {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
SimpleQueryStringQueryParser.Settings settings = new SimpleQueryStringQueryParser.Settings();
|
||||
settings.analyzeWildcard(true);
|
||||
settings.quoteFieldSuffix("_2");
|
||||
|
@ -575,7 +563,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testDefaultField() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
QueryShardContext context = createShardContext();
|
||||
context.getIndexSettings().updateIndexMetaData(
|
||||
newIndexMeta("index", context.getIndexSettings().getSettings(), Settings.builder().putList("index.query.default_field",
|
||||
|
@ -598,8 +585,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testToFuzzyQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
|
||||
Query query = new SimpleQueryStringBuilder("text~2")
|
||||
.field(STRING_FIELD_NAME)
|
||||
.fuzzyPrefixLength(2)
|
||||
|
@ -611,8 +596,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testLenientToPrefixQuery() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
|
||||
Query query = new SimpleQueryStringBuilder("t*")
|
||||
.field(DATE_FIELD_NAME)
|
||||
.field(STRING_FIELD_NAME)
|
||||
|
@ -626,7 +609,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testWithStopWords() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = new SimpleQueryStringBuilder("the quick fox")
|
||||
.field(STRING_FIELD_NAME)
|
||||
.analyzer("stop")
|
||||
|
@ -639,7 +621,6 @@ public class SimpleQueryStringBuilderTests extends AbstractQueryTestCase<SimpleQ
|
|||
}
|
||||
|
||||
public void testWithPrefixStopWords() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
Query query = new SimpleQueryStringBuilder("the* quick fox")
|
||||
.field(STRING_FIELD_NAME)
|
||||
.analyzer("stop")
|
||||
|
|
|
@ -138,7 +138,6 @@ public class TermQueryBuilderTests extends AbstractTermQueryTestCase<TermQueryBu
|
|||
}
|
||||
|
||||
public void testGeo() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
TermQueryBuilder query = new TermQueryBuilder(GEO_POINT_FIELD_NAME, "2,3");
|
||||
QueryShardContext context = createShardContext();
|
||||
QueryShardException e = expectThrows(QueryShardException.class, () -> query.toQuery(context));
|
||||
|
|
|
@ -264,7 +264,6 @@ public class TermsQueryBuilderTests extends AbstractQueryTestCase<TermsQueryBuil
|
|||
}
|
||||
|
||||
public void testGeo() throws Exception {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
TermsQueryBuilder query = new TermsQueryBuilder(GEO_POINT_FIELD_NAME, "2,3");
|
||||
QueryShardContext context = createShardContext();
|
||||
QueryShardException e = expectThrows(QueryShardException.class,
|
||||
|
|
|
@ -32,6 +32,7 @@ import java.io.IOException;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.test.AbstractBuilderTestCase.STRING_ALIAS_FIELD_NAME;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
|
@ -141,8 +142,6 @@ public class WildcardQueryBuilderTests extends AbstractQueryTestCase<WildcardQue
|
|||
}
|
||||
|
||||
public void testIndexWildcard() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
|
||||
QueryShardContext context = createShardContext();
|
||||
String index = context.getFullyQualifiedIndexName();
|
||||
|
||||
|
|
|
@ -256,17 +256,6 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
|||
assertThat(query, either(instanceOf(FunctionScoreQuery.class)).or(instanceOf(FunctionScoreQuery.class)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Overridden here to ensure the test is only run if at least one type is
|
||||
* present in the mappings. Functions require the field to be
|
||||
* explicitly mapped
|
||||
*/
|
||||
@Override
|
||||
public void testToQuery() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
super.testToQuery();
|
||||
}
|
||||
|
||||
public void testIllegalArguments() {
|
||||
expectThrows(IllegalArgumentException.class, () -> new FunctionScoreQueryBuilder((QueryBuilder) null));
|
||||
expectThrows(IllegalArgumentException.class, () -> new FunctionScoreQueryBuilder((ScoreFunctionBuilder<?>) null));
|
||||
|
@ -487,7 +476,6 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
|||
}
|
||||
|
||||
public void testWeight1fStillProducesWeightFunction() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
String queryString = Strings.toString(jsonBuilder().startObject()
|
||||
.startObject("function_score")
|
||||
.startArray("functions")
|
||||
|
@ -650,12 +638,6 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase<Functi
|
|||
assertEquals(json, 1, parsed.getMinScore(), 0.0001);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testMustRewrite() throws IOException {
|
||||
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
|
||||
super.testMustRewrite();
|
||||
}
|
||||
|
||||
public void testRewrite() throws IOException {
|
||||
FunctionScoreQueryBuilder functionScoreQueryBuilder =
|
||||
new FunctionScoreQueryBuilder(new WrapperQueryBuilder(new TermQueryBuilder("foo", "bar").toString()))
|
||||
|
|
|
@ -31,11 +31,7 @@ import org.elasticsearch.common.joda.Joda;
|
|||
import org.elasticsearch.index.query.QueryShardContext;
|
||||
import org.elasticsearch.search.aggregations.BaseAggregationTestCase;
|
||||
import org.elasticsearch.search.aggregations.BucketOrder;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval;
|
||||
import org.elasticsearch.search.aggregations.bucket.histogram.ExtendedBoundsTests;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.junit.Assume;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -141,7 +137,6 @@ public class DateHistogramTests extends BaseAggregationTestCase<DateHistogramAgg
|
|||
}
|
||||
|
||||
public void testRewriteTimeZone() throws IOException {
|
||||
Assume.assumeTrue(getCurrentTypes().length > 0); // we need mappings
|
||||
FormatDateTimeFormatter format = Joda.forPattern("strict_date_optional_time");
|
||||
|
||||
try (Directory dir = newDirectory();
|
||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.action.termvectors.MultiTermVectorsRequest;
|
|||
import org.elasticsearch.action.termvectors.MultiTermVectorsResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.metadata.MetaData;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.compress.CompressedXContent;
|
||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||
|
@ -40,7 +39,6 @@ import org.elasticsearch.common.settings.Setting;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.settings.SettingsModule;
|
||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||
import org.elasticsearch.core.internal.io.IOUtils;
|
||||
import org.elasticsearch.env.Environment;
|
||||
import org.elasticsearch.env.TestEnvironment;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
@ -129,20 +127,16 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
|
|||
protected static Version indexVersionCreated;
|
||||
|
||||
private static ServiceHolder serviceHolder;
|
||||
private static ServiceHolder serviceHolderWithNoType;
|
||||
private static int queryNameId = 0;
|
||||
private static Settings nodeSettings;
|
||||
private static Index index;
|
||||
private static String[] currentTypes;
|
||||
protected static String[] randomTypes;
|
||||
private static Index indexWithNoType;
|
||||
|
||||
protected static Index getIndex() {
|
||||
return index;
|
||||
}
|
||||
|
||||
protected static String[] getCurrentTypes() {
|
||||
return currentTypes;
|
||||
}
|
||||
|
||||
protected Collection<Class<? extends Plugin>> getPlugins() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -153,40 +147,12 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
|
|||
@BeforeClass
|
||||
public static void beforeClass() {
|
||||
nodeSettings = Settings.builder()
|
||||
.put("node.name", AbstractQueryTestCase.class.toString())
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
|
||||
.build();
|
||||
.put("node.name", AbstractQueryTestCase.class.toString())
|
||||
.put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
|
||||
.build();
|
||||
|
||||
index = new Index(randomAlphaOfLengthBetween(1, 10), "_na_");
|
||||
|
||||
// Set a single type in the index
|
||||
switch (random().nextInt(3)) {
|
||||
case 0:
|
||||
currentTypes = new String[0]; // no types
|
||||
break;
|
||||
default:
|
||||
currentTypes = new String[] { "_doc" };
|
||||
break;
|
||||
}
|
||||
randomTypes = getRandomTypes();
|
||||
}
|
||||
|
||||
private static String[] getRandomTypes() {
|
||||
String[] types;
|
||||
if (currentTypes.length > 0 && randomBoolean()) {
|
||||
int numberOfQueryTypes = randomIntBetween(1, currentTypes.length);
|
||||
types = new String[numberOfQueryTypes];
|
||||
for (int i = 0; i < numberOfQueryTypes; i++) {
|
||||
types[i] = randomFrom(currentTypes);
|
||||
}
|
||||
} else {
|
||||
if (randomBoolean()) {
|
||||
types = new String[]{MetaData.ALL};
|
||||
} else {
|
||||
types = new String[0];
|
||||
}
|
||||
}
|
||||
return types;
|
||||
index = new Index(randomAlphaOfLengthBetween(1, 10), randomAlphaOfLength(10));
|
||||
indexWithNoType = new Index(randomAlphaOfLengthBetween(1, 10), randomAlphaOfLength(10));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -210,34 +176,37 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
|
|||
protected Settings indexSettings() {
|
||||
// we have to prefer CURRENT since with the range of versions we support it's rather unlikely to get the current actually.
|
||||
indexVersionCreated = randomBoolean() ? Version.CURRENT
|
||||
: VersionUtils.randomVersionBetween(random(), null, Version.CURRENT);
|
||||
: VersionUtils.randomVersionBetween(random(), Version.V_6_0_0, Version.CURRENT);
|
||||
return Settings.builder()
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated)
|
||||
.build();
|
||||
}
|
||||
|
||||
protected static String expectedFieldName(String builderFieldName) {
|
||||
if (currentTypes.length == 0) {
|
||||
return builderFieldName;
|
||||
}
|
||||
return ALIAS_TO_CONCRETE_FIELD_NAME.getOrDefault(builderFieldName, builderFieldName);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
IOUtils.close(serviceHolder);
|
||||
org.apache.lucene.util.IOUtils.close(serviceHolder);
|
||||
org.apache.lucene.util.IOUtils.close(serviceHolderWithNoType);
|
||||
serviceHolder = null;
|
||||
serviceHolderWithNoType = null;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void beforeTest() throws IOException {
|
||||
if (serviceHolder == null) {
|
||||
serviceHolder = new ServiceHolder(nodeSettings, indexSettings(), getPlugins(), this);
|
||||
serviceHolder = new ServiceHolder(nodeSettings, indexSettings(), getPlugins(), this, true);
|
||||
}
|
||||
serviceHolder.clientInvocationHandler.delegate = this;
|
||||
if (serviceHolderWithNoType == null) {
|
||||
serviceHolderWithNoType = new ServiceHolder(nodeSettings, indexSettings(), getPlugins(), this, false);
|
||||
}
|
||||
serviceHolderWithNoType.clientInvocationHandler.delegate = this;
|
||||
}
|
||||
|
||||
protected static SearchContext getSearchContext(String[] types, QueryShardContext context) {
|
||||
protected static SearchContext getSearchContext(QueryShardContext context) {
|
||||
TestSearchContext testSearchContext = new TestSearchContext(context) {
|
||||
@Override
|
||||
public MapperService mapperService() {
|
||||
|
@ -250,13 +219,13 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
|
|||
}
|
||||
|
||||
};
|
||||
testSearchContext.getQueryShardContext().setTypes(types);
|
||||
return testSearchContext;
|
||||
}
|
||||
|
||||
@After
|
||||
public void afterTest() {
|
||||
serviceHolder.clientInvocationHandler.delegate = null;
|
||||
serviceHolderWithNoType.clientInvocationHandler.delegate = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -280,6 +249,13 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
|
|||
return serviceHolder.createShardContext(reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new {@link QueryShardContext} based on an index with no type registered
|
||||
*/
|
||||
protected static QueryShardContext createShardContextWithNoType() {
|
||||
return serviceHolderWithNoType.createShardContext(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a new {@link QueryShardContext} based on the base test index and queryParserService
|
||||
*/
|
||||
|
@ -331,8 +307,11 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
|
|||
private final Client client;
|
||||
private final long nowInMillis = randomNonNegativeLong();
|
||||
|
||||
ServiceHolder(Settings nodeSettings, Settings indexSettings,
|
||||
Collection<Class<? extends Plugin>> plugins, AbstractBuilderTestCase testCase) throws IOException {
|
||||
ServiceHolder(Settings nodeSettings,
|
||||
Settings indexSettings,
|
||||
Collection<Class<? extends Plugin>> plugins,
|
||||
AbstractBuilderTestCase testCase,
|
||||
boolean registerType) throws IOException {
|
||||
Environment env = InternalSettingsPreparer.prepareEnvironment(nodeSettings);
|
||||
PluginsService pluginsService;
|
||||
pluginsService = new PluginsService(nodeSettings, null, env.modulesFile(), env.pluginsFile(), plugins);
|
||||
|
@ -379,9 +358,8 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
|
|||
}
|
||||
});
|
||||
|
||||
|
||||
for (String type : currentTypes) {
|
||||
mapperService.merge(type, new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef(type,
|
||||
if (registerType) {
|
||||
mapperService.merge("_doc", new CompressedXContent(Strings.toString(PutMappingRequest.buildFromSimplifiedDef("_doc",
|
||||
STRING_FIELD_NAME, "type=text",
|
||||
STRING_FIELD_NAME_2, "type=keyword",
|
||||
STRING_ALIAS_FIELD_NAME, "type=alias,path=" + STRING_FIELD_NAME,
|
||||
|
@ -399,12 +377,12 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
|
|||
GEO_SHAPE_FIELD_NAME, "type=geo_shape"
|
||||
))), MapperService.MergeReason.MAPPING_UPDATE);
|
||||
// also add mappings for two inner field in the object field
|
||||
mapperService.merge(type, new CompressedXContent("{\"properties\":{\"" + OBJECT_FIELD_NAME + "\":{\"type\":\"object\","
|
||||
+ "\"properties\":{\"" + DATE_FIELD_NAME + "\":{\"type\":\"date\"},\"" +
|
||||
INT_FIELD_NAME + "\":{\"type\":\"integer\"}}}}}"),
|
||||
MapperService.MergeReason.MAPPING_UPDATE);
|
||||
mapperService.merge("_doc", new CompressedXContent("{\"properties\":{\"" + OBJECT_FIELD_NAME + "\":{\"type\":\"object\","
|
||||
+ "\"properties\":{\"" + DATE_FIELD_NAME + "\":{\"type\":\"date\"},\"" +
|
||||
INT_FIELD_NAME + "\":{\"type\":\"integer\"}}}}}"),
|
||||
MapperService.MergeReason.MAPPING_UPDATE);
|
||||
testCase.initializeAdditionalMappings(mapperService);
|
||||
}
|
||||
testCase.initializeAdditionalMappings(mapperService);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -423,5 +401,4 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
|
|||
return new ScriptModule(Settings.EMPTY, scriptPlugins);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -413,7 +413,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
context.setAllowUnmappedFields(true);
|
||||
QB firstQuery = createTestQueryBuilder();
|
||||
QB controlQuery = copyQuery(firstQuery);
|
||||
SearchContext searchContext = getSearchContext(randomTypes, context);
|
||||
SearchContext searchContext = getSearchContext(context);
|
||||
/* we use a private rewrite context here since we want the most realistic way of asserting that we are cacheable or not.
|
||||
* We do it this way in SearchService where
|
||||
* we first rewrite the query with a private context, then reset the context and then build the actual lucene query*/
|
||||
|
@ -443,7 +443,7 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
secondQuery.queryName(secondQuery.queryName() == null ? randomAlphaOfLengthBetween(1, 30) : secondQuery.queryName()
|
||||
+ randomAlphaOfLengthBetween(1, 10));
|
||||
}
|
||||
searchContext = getSearchContext(randomTypes, context);
|
||||
searchContext = getSearchContext(context);
|
||||
Query secondLuceneQuery = rewriteQuery(secondQuery, context).toQuery(context);
|
||||
assertNotNull("toQuery should not return null", secondLuceneQuery);
|
||||
assertLuceneQuery(secondQuery, secondLuceneQuery, searchContext);
|
||||
|
@ -668,10 +668,11 @@ public abstract class AbstractQueryTestCase<QB extends AbstractQueryBuilder<QB>>
|
|||
*/
|
||||
protected static String getRandomFieldName() {
|
||||
// if no type is set then return a random field name
|
||||
if (getCurrentTypes().length == 0 || randomBoolean()) {
|
||||
if (randomBoolean()) {
|
||||
return randomAlphaOfLengthBetween(1, 10);
|
||||
} else {
|
||||
return randomFrom(MAPPED_LEAF_FIELD_NAMES);
|
||||
}
|
||||
return randomFrom(MAPPED_LEAF_FIELD_NAMES);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue