Search in sources :

Example 1 with ShapeType

use of org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType in project elasticsearch by elastic.

the class GeoShapeQueryBuilderTests method testIgnoreUnmapped.

public void testIgnoreUnmapped() throws IOException {
    ShapeType shapeType = ShapeType.randomType(random());
    ShapeBuilder shape = RandomShapeGenerator.createShapeWithin(random(), null, shapeType);
    final GeoShapeQueryBuilder queryBuilder = new GeoShapeQueryBuilder("unmapped", shape);
    queryBuilder.ignoreUnmapped(true);
    Query query = queryBuilder.toQuery(createShardContext());
    assertThat(query, notNullValue());
    assertThat(query, instanceOf(MatchNoDocsQuery.class));
    final GeoShapeQueryBuilder failingQueryBuilder = new GeoShapeQueryBuilder("unmapped", shape);
    failingQueryBuilder.ignoreUnmapped(false);
    QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext()));
    assertThat(e.getMessage(), containsString("failed to find geo_shape field [unmapped]"));
}
Also used : ShapeBuilder(org.elasticsearch.common.geo.builders.ShapeBuilder) Query(org.apache.lucene.search.Query) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) ConstantScoreQuery(org.apache.lucene.search.ConstantScoreQuery) BooleanQuery(org.apache.lucene.search.BooleanQuery) MatchNoDocsQuery(org.apache.lucene.search.MatchNoDocsQuery) ShapeType(org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType)

Example 2 with ShapeType

use of org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType in project elasticsearch by elastic.

the class GeoShapeQueryBuilderTests method doCreateTestQueryBuilder.

@Override
protected GeoShapeQueryBuilder doCreateTestQueryBuilder() {
    ShapeType shapeType = ShapeType.randomType(random());
    ShapeBuilder shape = RandomShapeGenerator.createShapeWithin(random(), null, shapeType);
    GeoShapeQueryBuilder builder;
    clearShapeFields();
    if (randomBoolean()) {
        builder = new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, shape);
    } else {
        indexedShapeToReturn = shape;
        indexedShapeId = randomAsciiOfLengthBetween(3, 20);
        indexedShapeType = randomAsciiOfLengthBetween(3, 20);
        builder = new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, indexedShapeId, indexedShapeType);
        if (randomBoolean()) {
            indexedShapeIndex = randomAsciiOfLengthBetween(3, 20);
            builder.indexedShapeIndex(indexedShapeIndex);
        }
        if (randomBoolean()) {
            indexedShapePath = randomAsciiOfLengthBetween(3, 20);
            builder.indexedShapePath(indexedShapePath);
        }
    }
    if (randomBoolean()) {
        SpatialStrategy strategy = randomFrom(SpatialStrategy.values());
        // we try to avoid that combination
        while (shapeType == ShapeType.MULTILINESTRING && strategy == SpatialStrategy.TERM) {
            strategy = randomFrom(SpatialStrategy.values());
        }
        builder.strategy(strategy);
        if (strategy != SpatialStrategy.TERM) {
            builder.relation(randomFrom(ShapeRelation.values()));
        }
    }
    if (randomBoolean()) {
        builder.ignoreUnmapped(randomBoolean());
    }
    return builder;
}
Also used : ShapeBuilder(org.elasticsearch.common.geo.builders.ShapeBuilder) ShapeType(org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType) SpatialStrategy(org.elasticsearch.common.geo.SpatialStrategy)

Aggregations

ShapeBuilder (org.elasticsearch.common.geo.builders.ShapeBuilder)2 ShapeType (org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType)2 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 ConstantScoreQuery (org.apache.lucene.search.ConstantScoreQuery)1 MatchNoDocsQuery (org.apache.lucene.search.MatchNoDocsQuery)1 Query (org.apache.lucene.search.Query)1 SpatialStrategy (org.elasticsearch.common.geo.SpatialStrategy)1