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